function oboutCalendar(	Id, 
							Speed, 
							MonthWidth, 
							MonthHeight, 
							MarginWidth, 
							Rows, 
							Cols, 
							StartDate, 
							DateMin, 
							DateMax, 
							DateToday,
							LongMonthNames,
							ShortMonthNames,
							LongDayNames,
							ShortDayNames,
							ScrollBy,
							SpecialDates,
							SpecialDatesStyles,
							SpecialDatesStylesOver,
							SpecialDatesTooltips,
							SpecialDatesUrls,
							SelectedDate,
							SelectedDates,
							StartDateCalendar,
							DatePickerMode,
							OffsetLeft,
							OffsetTop,
							TextBoxId,
							DateFormat,
							MonthYearFormat,
							FirstDayOfWeek,
							ShowOtherMonthDays,
							AllowDeselect,
							AllowSelectSpecial,
							AllowSelectRegular,
							EnabledDateExpression,
							PostBackCode,
							Enabled,
							DatePickerSynchronize,
							MultiSelectedDates,

							StyleMonth,
							StyleMonthTitle,
							StyleDayName,
							StyleDay,
							StyleDayOver,
							StyleDayDisabled,
							StyleDayDisabledOver,
							StyleDaySpecial,
							StyleDaySpecialOver,
							StyleDayToday,
							StyleDayTodayOver,
							StyleDaySelected,
							StyleDaySelectedOver,
							
							StyleYearSelector,
							StyleYearSelected,
							
							StyleMonthSelector,
							StyleMonthSelected,
							
							StyleHourSelector,
							StyleHourSelected,
							
							StyleMinuteSelector,
							StyleMinuteSelected,
							
							StyleSecondSelector,
							StyleSecondSelected,
							
							YearSelectorScrollSpeed,
							FirstYearSelectorScrollSpeed,
							
							HourSelectorScrollSpeed,
							FirstHourSelectorScrollSpeed,
							
							MinuteSelectorScrollSpeed,
							FirstMinuteSelectorScrollSpeed,
							
							SecondSelectorScrollSpeed,
							FirstSecondSelectorScrollSpeed,
							
							ShowYearSelector,
							ShowMonthSelector,
							
							Align
							) {
	// on each new initialization drop the previous object, if exists

    try
	{
	    var currObject = eval(Id);
	    if (currObject != null)
	    {
	        eval(Id + "=null;");
	        this.calendarEmpty = true;
	    }
	}
	catch(ex){}
	this.id = Id;
	this.speed = Speed;
	this.speed_basic = Speed;
	this.monthWidth = MonthWidth;
	this.monthHeight = MonthHeight;
	this.marginWidth = MarginWidth;
	this.rows = Rows;
	this.cols = Cols;
	this.startDate = StartDate;
	this.firstMonth = this.lastMonth = StartDate.getMonth();
	this.firstYear = this.lastYear = StartDate.getFullYear();
	this.lastHour = StartDate.getHours();
	this.dateMin = DateMin;
	this.dateMax = DateMax;
	this.dateToday = DateToday;
	this.longMonthNames = LongMonthNames.split(',');
	this.shortMonthNames = ShortMonthNames.split(',');
	this.longDayNames = LongDayNames.split(',');
	this.shortDayNames = ShortDayNames.split(',');
	this.actionQueue = new Array();
	this.isWorking=false;
	if(ScrollBy > this.cols) {this.slideBy = this.cols;}
	else {this.slideBy = ScrollBy;}
	this.scrollBy = ScrollBy;
	this.selectedDate = SelectedDate;
	this.selectedDates = SelectedDates;
	this.selectedCell = null;
	this.startDateCalendarId = StartDateCalendar;
	this.startDateCalendar = null;
	this.endDateCalendar = null;
	this.datePickerMode = DatePickerMode;
	this.offsetLeft = OffsetLeft;
	this.offsetTop = OffsetTop;
	this.textBoxId = TextBoxId;
	this.textbox = null;
	this.dateFormat = DateFormat;
	this.monthYearFormat = MonthYearFormat;
	this.firstDayOfWeek = FirstDayOfWeek;
	this.showOtherMonthDays = ShowOtherMonthDays;
	this.allowDeselect = AllowDeselect;
	this.allowSelectSpecial = AllowSelectSpecial;
	this.allowSelectRegular = AllowSelectRegular;
	this.didOnceOnSelect = false;
	this.enabledDateExpression = EnabledDateExpression;
	this.hiddenField = null;
	this.hiddenFieldSD = null;
	this.postBackCode = PostBackCode;
	this.enabled = Enabled;
	this.datePickerSynchronize = DatePickerSynchronize;
	this.multiSelectedDates = MultiSelectedDates;
	this.showYearSelector = ShowYearSelector;
	this.showMonthSelector = ShowMonthSelector;
	this.currentDate = null;
	// style properties
	this.styleMonth = StyleMonth;
	this.styleMonthTitle = StyleMonthTitle;
	this.styleDayName = StyleDayName;
	this.styleDay = StyleDay;
	this.styleDayOver = StyleDayOver;
	this.styleDayDisabled = StyleDayDisabled;
	this.styleDayDisabledOver = StyleDayDisabledOver;
	this.styleDaySpecial = StyleDaySpecial;
	this.styleDaySpecialOver = StyleDaySpecialOver;
	this.styleDayToday = StyleDayToday;
	this.styleDayTodayOver = StyleDayTodayOver;
	this.styleDaySelected = StyleDaySelected;
	this.styleDaySelectedOver = StyleDaySelectedOver;
	
	this.styleYearSelector = StyleYearSelector;
	this.styleYearSelected = StyleYearSelected;
	
	this.styleMonthSelector = StyleMonthSelector;
	this.styleMonthSelected = StyleMonthSelected;
	
	this.styleHourSelector = StyleHourSelector;
	this.styleHourSelected = StyleHourSelected;
	
	this.styleMinuteSelector = StyleMinuteSelector;
	this.styleMinuteSelected = StyleMinuteSelected;
	
	this.styleSecondSelector = StyleSecondSelector;
	this.styleSecondSelected = StyleSecondSelected;
	
	// scrolling speed for the year selector
	this.yearSelectorScrollSpeed = YearSelectorScrollSpeed;
	this.firstYearSelectorScrollSpeed = FirstYearSelectorScrollSpeed;
	
	this.hourSelectorScrollSpeed = HourSelectorScrollSpeed;
	this.firstHourSelectorScrollSpeed = FirstHourSelectorScrollSpeed;
	
	this.minuteSelectorScrollSpeed = MinuteSelectorScrollSpeed;
	this.firstMinuteSelectorScrollSpeed = FirstMinuteSelectorScrollSpeed;
	
	this.secondSelectorScrollSpeed = SecondSelectorScrollSpeed;
	this.firstSecondSelectorScrollSpeed = FirstSecondSelectorScrollSpeed;
	
	// align properties
	this.Align = Align;
	
	this.timeSelector = ((document.getElementById("_" + this.id + "Hour") != null) || (document.getElementById(this.id + "_HourSelectorTitle") != null));
	
	// arrange SpecialDates properly
	var i=0;
	this.specialDates = new Object();
	this.specialDatesStyles = new Object();
	this.specialDatesStylesOver = new Object();
	this.specialDatesUrls = new Object();
	
	//SpecialDates = new Array(new Date(2007,5,20),new Date(2007,5,8),new Date(-1,6,4),new Date(2007,6,18)),
	//SpecialDatesTooltips = new Array("Dentist appointment","Some tooltip","Independence Day","A tooltip")
	//SpecialDatesStyles = new Array("medica","css1","indepDay","css2"),
	//SpecialDatesStylesOver = new Array("medicaOver","css1over","indepDayOver","css2Over"),
	//SpecialDatesUrls = new Array("","","http://en.wikipedia.org/wiki/Independence_Day_%28United_States%29","")
	for (i = 0; i < SpecialDates.length; i++) {
		this.specialDates[SpecialDates[i].valueOf()]=SpecialDatesTooltips[i];
		this.specialDatesUrls[SpecialDates[i].valueOf()] = SpecialDatesUrls[i];
		if(SpecialDatesStyles[i] == "") {
			this.specialDatesStyles[SpecialDates[i].valueOf()] = this.styleDaySpecial;
		}
		else {
			this.specialDatesStyles[SpecialDates[i].valueOf()] = SpecialDatesStyles[i];
		}
		if(SpecialDatesStylesOver[i] == "") {
			this.specialDatesStylesOver[SpecialDates[i].valueOf()] = this.styleDaySpecialOver;
		}
		else {
			this.specialDatesStylesOver[SpecialDates[i].valueOf()] = SpecialDatesStylesOver[i];
		}
	}

	if (this.datePickerMode && this.datePickerSynchronize)//Initialize for both Calendar date change and Textbox text change event handler
	{
	    this.initDatePickerTextbox();
	    this.initCalendar();
	}
	else if (!this.datePickerMode) // non datepicker mode
	    this.initCalendar();
	else
	    this.initDatePickerTextbox(); //Initialize for Calendar date change
};

oboutCalendar.prototype.initCalendar =
function () {
    this.initStarted = true;
    var col, td, tr;
    this.isWorking = false;
    this.isVisible = false;
    this.isIE = (navigator.userAgent.toLowerCase().indexOf("msie") == -1) ? false : true;
    this.isSafari = (this.isIE || navigator.userAgent.toLowerCase().indexOf("safari") == -1) ? false : true;
    this.isFF = (this.isIE || this.isSafari || navigator.userAgent.toLowerCase().indexOf("firefox") == -1) ? false : true;
    this.isOpera = (this.isFF || this.isIE || this.isSafari || navigator.userAgent.toLowerCase().indexOf("opera") == -1) ? false : true;

    this.calendarWidth = (this.cols * this.monthWidth); // this.cols = how many months to show in view, product of number of minths and month's width is the width of the Calendar control 
    this.calendarContainer = document.getElementById("_" + this.id + "Container");

    if (this.calendarContainer.firstChild.nextSibling) {
        this.outerTable = this.calendarContainer.firstChild.nextSibling.firstChild;
    }
    else {
        this.outerTable = this.calendarContainer.firstChild.firstChild;
    }
    // set calendar size
    this.calendarContainer.style.width = (this.calendarWidth + this.marginWidth) + "px";
    this.outerTable.style.margin = (this.marginWidth / 2) + "px";
    if (this.datePickerMode) {
        this.button = document.getElementById("_" + this.id + "Button");
        this.iframe = document.getElementById("_" + this.id + "iframe");
    }

    // empty the calendar container (months)
    if (this.calendarEmpty) {
        while (this.outerTable.firstChild.firstChild.hasChildNodes()) {
            if (document.addEventListener && typeof this.outerTable.firstChild.firstChild.blur == 'function')
                this.outerTable.firstChild.firstChild.blur();

            this.outerTable.firstChild.firstChild.removeChild(this.outerTable.firstChild.firstChild.firstChild);
        }
    }
    tr = this.outerTable.firstChild.firstChild;
    this.firstMonth = this.lastMonth;
    this.firstYear = this.lastYear;
    for (col = 0; col < this.cols; col++) {
        // append a cell to outer table and set its width
        td = tr.appendChild(document.createElement("td"));
        td.style.width = this.monthWidth + "px";
        // build months table
        //td.appendChild(this.buildMonthsTable());
        td.appendChild(this.buildMonthColumn());
        if (this.rows == 1) { this.incrementMonth(1); }
        else { this.incrementMonth(-(this.cols * this.rows - this.cols - 1)); };

    }
    if (this.rows == 1) { this.incrementMonth(-1); }
    else { this.incrementMonth(this.cols * this.rows - this.cols - 1); };
    if (!this.datePickerMode) {
        this.calendarContainer.style.display = "block";
    }

    this.hiddenField = document.getElementsByName("h_" + this.id)[0]; // try to get the hidden field for postback
    this.hiddenFieldSD = document.getElementsByName("sd_" + this.id)[0]; // try to get the hidden field for postback
    this.setHiddenFieldSD();

    this.init = true;
    this.initStarted = false;
};

oboutCalendar.prototype.textboxChangeEvent = 
function() {
    //parse textbox date
	if(this.textbox != null && this.datePickerSynchronize && this.textbox.value != "") {
		var newDate = this.extractDate(this.textbox.value, this.dateFormat);
		if((!isNaN(newDate) && this.selectedDate != null && this.compareDates(newDate, this.selectedDate) != 0) || !isNaN(newDate))
		{
		    this.switchViewWorking = true;
		    this.speed = 1000;
		    
            //this.addToQueue(this.id + "." + (("switchView")) + "(new Date(" + newDate.getFullYear() + "," + newDate.getMonth() + "," + newDate.getDate() + "," + newDate.getHours() + "," + newDate.getMinutes() + "," + newDate.getSeconds() + ",0)" + "," + " new Date(" + newDate.getFullYear() + "," + newDate.getMonth() + "," + newDate.getDate() + "," + newDate.getHours() + "," + newDate.getMinutes() + "," + newDate.getSeconds() + ",0), " + ((this.startDateCalendar != null)?"false":"true") + ");");
            this.switchView(new Date(newDate.getFullYear(),newDate.getMonth(),newDate.getDate(),newDate.getHours(),newDate.getMinutes(),newDate.getSeconds(),0),new Date(newDate.getFullYear(),newDate.getMonth(),newDate.getDate(),newDate.getHours(),newDate.getMinutes(),newDate.getSeconds(),0),(this.startDateCalendar != null)?"false":"true");
        }
	}
}

oboutCalendar.prototype.initDatePickerTextbox =
function() {
    this.textbox = document.getElementById(this.textBoxId);

    if (this.textbox != null) {
       //If not IE
        if (this.textbox.addEventListener) {
            var FunctionName = this.id + ".textboxChangeEvent();";
            this.attachEventHandler(this.textbox, "change",
                function() {
                    eval(FunctionName);                    
                }
            );
            }
        //If IE
        else {
            this.attachEventHandler(this.textbox, "change", new Function(this.id + ".textboxChangeEvent();"));
        }
    }

    // if textbox exists and have selected date, then fill the textbox
    if (this.textbox != null && this.selectedDate != null) {
        this.textbox.value = this.formatDate(this.selectedDate, this.dateFormat);
    }
}


oboutCalendar.prototype.buildMonthColumn =
function() {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();

	var row, tableRow, tmp, tbody;
	var table = document.createElement("table");
	if(this.isIE) {
		table.border = 0;
		table.cellSpacing = 0;
		table.cellPadding = 0;
	}
	else {
		table.setAttribute("border", 0);
		table.setAttribute("cellspacing", 0);
		table.setAttribute("cellpadding", 0);
	}
	tbody = table.appendChild(document.createElement("tbody"));
	tableRow = tbody.appendChild(document.createElement("tr"));
	//loop through rows for a column
	for(row=0;row<this.rows;row++) {
		tableRow = tbody.appendChild(document.createElement("tr"));
		tmp = tableRow.appendChild(document.createElement("td"));
		tmp.style.width = this.monthWidth + "px";
		tmp = tmp.appendChild(document.createElement("div"));
		tmp.style.height = this.monthHeight + "px";
		tmp.style.margin = (this.marginWidth/2)+"px";
		tmp.appendChild(this.buildMonth());
		if(this.rows==1) {this.incrementMonth(1);}
		else {this.incrementMonth(this.cols);};
	}
	if(this.rows==1) {this.incrementMonth(-1);}
	else {this.incrementMonth(-this.cols);};
	return table;
};

//To nevigate to next month in the view
oboutCalendar.prototype.appendMonths =
function() {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();

    var td;
    if (this.rows > 1 && this.scrollBy > this.slideBy) {
        this.incrementMonth(this.cols * this.rows - this.cols);
    }
    this.firstMonth = this.lastMonth;
    this.firstYear = this.lastYear;
    for (var i = 0; i < this.slideBy; i++) {
        // set lastdate to the needed cell
        this.incrementMonth(-(this.cols * this.rows - this.cols - 1));
        // append months
        td = this.outerTable.firstChild.firstChild.appendChild(document.createElement("td"));
        td.style.width = this.monthWidth + "px";
        td.appendChild(this.buildMonthColumn());
    }
    //move table to left
    this.leftPos = 0;
    //add to execution queue
    this.timer = eval("window.setInterval(\"" + this.id + "." + (("slide")) + "(-1)\", 1)");

    // change the year selector selected date (set the first month's year)
    var firstYear = this.lastYear;
    var firstMonth = (this.lastMonth + 12 - (this.cols * this.rows) + 1) % 12;
    if (firstMonth > this.lastMonth) firstYear = firstYear - 1;
    if (this.showYearSelector) this.updateYearSelector(firstYear);

    // change the month selector selected month
    if (this.showMonthSelector) this.updateMonthSelector((this.lastMonth + 12 - (this.cols * this.rows) + 1) % 12);

    // execute the client side event 
    this.MonthScrollRightEvent();
    this.SwitchViewEvent();
};


//To nevigate to previous month in the view
oboutCalendar.prototype.prependMonths =
function() {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();

    var td;
	// set lastdate to the needed cell
	if(this.rows>1 && this.scrollBy > this.slideBy) {
		this.incrementMonth(-2*this.cols*this.rows+this.cols);
	} else {
		this.incrementMonth(-this.cols*this.rows);
    }

    this.firstMonth = this.lastMonth;
    this.firstYear = this.lastYear;
	for(var i=0; i<this.slideBy; i++) {
		// prepend months
		td = this.outerTable.firstChild.firstChild.insertBefore(document.createElement("td"), this.outerTable.firstChild.firstChild.firstChild);
		td.style.width = this.monthWidth + "px";
		this.outerTable.style.left = (-this.monthWidth*(i+1))+"px";
		td.appendChild(this.buildMonthColumn());
		this.incrementMonth(-(this.cols*this.rows-this.cols+1));
	}
	this.incrementMonth(this.cols*this.rows);
	//move table to right
	this.leftPos = -this.monthWidth * this.slideBy;
	//add to execution queue
	this.timer = eval("window.setInterval(\"" + this.id + "." + (("slide")) + "(1)\", 1)");
	
	// change the year selector selected date (set the first month's year)
	var firstYear = this.lastYear;
	var firstMonth = (this.lastMonth + 12 - (this.cols * this.rows) + 1) % 12;
	if (firstMonth > this.lastMonth)  firstYear = firstYear - 1;
	if (this.showYearSelector) this.updateYearSelector(firstYear);
	
	// change the month selector selected month
	if (this.showMonthSelector) this.updateMonthSelector((this.lastMonth + 12 - (this.cols * this.rows) + 1) % 12);
	
	// execute the client side event
	this.MonthScrollLeftEvent();
	this.SwitchViewEvent();
};

oboutCalendar.prototype.switchView =
function(newDate, selDate, firstCell) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    var tr, td;
	if(this.outerTable.parentNode.offsetHeight != 0) {
		this.outerTable.parentNode.style.height = this.outerTable.parentNode.offsetHeight + "px";
	}
	if(selDate != null) {this.selectedDate = selDate;};
	if(newDate != null) {
		this.lastMonth = newDate.getMonth();
		this.lastYear = newDate.getFullYear();
	}
	if(!firstCell) {
		this.incrementMonth(-this.cols*this.rows+1);
	}
	
	// set the desired time if available
	if (this.timeSelector)
	{
	    if (selDate != null)
	        this.setTime(selDate.getHours(), selDate.getMinutes(), selDate.getSeconds());
	    else
	        this.setTime(0, 0, 0);
	}
	
	if(this.hiddenField != null && selDate != null) {
	    // add also the selected time
	    var time = this.getTime();
	    var timeString = "";
	    if (time != null)    
	        timeString = ";" + time["Hour"] + "." + time["Minute"] + "." + time["Second"];
		this.hiddenField.value = selDate.getFullYear()+"."+(selDate.getMonth()+1)+"."+selDate.getDate()+";"+this.lastYear+"."+(this.lastMonth+1)+".1" + timeString;
	}
	
	this.setHiddenFieldSD();
	    
	//append new row to outer table
	tr = this.outerTable.firstChild.appendChild(document.createElement("tr"));
	this.firstMonth = this.lastMonth;
	this.firstYear = this.lastYear;
	for (col = 0; col < this.cols; col++) {
		// append a cell to outer table and set its width
		td = tr.appendChild(document.createElement("td"));
		td.style.width = this.monthWidth + "px";
		// build months table
		td.appendChild(this.buildMonthColumn());
		if(this.rows == 1) {this.incrementMonth(1);}
		else {this.incrementMonth(-(this.cols*this.rows-this.cols-1));};
	}
	if(this.rows == 1) {this.incrementMonth(-1);}
	else {this.incrementMonth(this.cols*this.rows-this.cols-1);};
	this.leftPos = 0;
	
	if (this.switchViewWorking)
	    this.slide(0);
	else
	    this.timer = eval("window.setInterval(\"" + this.id + "." + (("slide")) + "(0)\", 1)");
	
	this.SwitchViewEvent();
};

oboutCalendar.prototype.switchViewWorking = false;

oboutCalendar.prototype.slide =
function(dir) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
	if(dir<0) {  // if moving left
		this.leftPos-=this.speed;
		if(this.monthWidth * this.slideBy + this.leftPos >= 0) { // if need to scroll
			if(this.monthWidth * this.slideBy + this.leftPos < this.speed) { // we don't want to overscroll
				this.outerTable.style.left = (-this.monthWidth * this.slideBy)+"px";
			}
			else {
				this.outerTable.style.left=this.leftPos+"px";
			}
		}
		else {
			window.clearInterval(this.timer);
			//remove left td
			var tableRow = this.outerTable.firstChild.firstChild;
			for(var i=0; i<this.slideBy; i++) {
				//this.cleanUp(tableRow.firstChild);
				tableRow.removeChild(tableRow.firstChild);
				this.outerTable.style.left=(-this.monthWidth*(this.slideBy-i-1))+"px";
			};
			tableRow=null;
			this.isWorking=false;

			this.switchViewWorking = false;
			this.speed = this.speed_basic;
			
			this.checkQueue();
		}
	}
	else if(dir>0) {
		this.leftPos+=this.speed;
		if(this.leftPos < 0) { // if need to scroll
			if(this.leftPos + this.speed > 0) { // we don't want to overscroll
				this.outerTable.style.left = "0px";
			}
			else {
				this.outerTable.style.left=this.leftPos + "px";
			}
		}
		else {
			window.clearInterval(this.timer);
			//remove right td
			var tableRow = this.outerTable.firstChild.firstChild;
			for(var i=0; i<this.slideBy; i++) {
				//this.cleanUp(tableRow.childNodes[tableRow.childNodes.length - 1]);
				tableRow.removeChild(tableRow.childNodes[tableRow.childNodes.length - 1]);
			};
			tableRow=null;
			this.outerTable.style.left="0px";
			this.isWorking=false;

			this.switchViewWorking = false;
			this.speed = this.speed_basic;
			
			this.checkQueue();
		}
	}
	else {
		this.leftPos-=this.speed;
		if(this.monthHeight * this.rows + this.leftPos >= 0) {
			if(this.monthHeight * this.rows + this.leftPos < this.speed) {
				this.outerTable.style.top = (-this.monthHeight * this.rows)+"px";
			}
			else {
				this.outerTable.style.top = this.leftPos + "px";
			}
		}
		else {
			window.clearInterval(this.timer);
			//remove top td
			this.outerTable.firstChild.removeChild(this.outerTable.firstChild.firstChild);
			this.outerTable.style.top="0px";
			this.isWorking=false;

			this.switchViewWorking = false;
			this.speed = this.speed_basic;
			
			this.checkQueue();
		}
	}
};


//Render the days of the months on the view, with special dates, selected dates and DateExpression
//In 6 row ( for 6 weeks), 7 column ( 7 weekdays) for each month
oboutCalendar.prototype.buildMonth =
function() {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();

    var data = new Date(this.lastYear, this.lastMonth, 1, 9, 0, 0, 999);
    this.currentDate = new Date(this.lastYear, this.lastMonth, 1, 9, 0, 0, 999);
    var col = 0;
    var row = 0;
    var table, tbody, tablerow, tablecol, specialDateUrl;
    var dayWidth = Math.floor((this.monthWidth - this.marginWidth) / 7);
    table = document.createElement("table");
    table.style.width = "100%";
    table.style.height = "100%";
    if (!this.isIE) {
        table.style.tableLayout = "fixed";// If IE, the table layout can stretch to accomodate styles.
    }
    this.changeStyle(table, this.styleMonth);
    tbody = table.appendChild(document.createElement("tbody"));
    //month title
    tablerow = tbody.appendChild(document.createElement("tr"));
    tablecol = tablerow.appendChild(document.createElement("td"));
    if (this.isIE) {
        tablecol.colSpan = 7;
        table.border = 0;
        table.cellSpacing = 0;
        table.cellPadding = 0;
    }
    else {
        tablecol.setAttribute("colspan", 7);
        table.setAttribute("border", 0);
        table.setAttribute("cellspacing", 0);
        table.setAttribute("cellpadding", 0);
    }

    tablecol.appendChild(document.createTextNode
    (this.formatDate(new Date(this.lastYear, this.lastMonth, 1, 9, 0, 0, 999), this.monthYearFormat)));
    //this.longMonthNames[this.lastMonth] + ", " + this.lastYear));
    this.changeStyle(tablecol, this.styleMonthTitle);
    //day names
    tablerow = tbody.appendChild(document.createElement("tr"));
    for (col = 0; col < 7; col++) {
        tablecol = tablerow.appendChild(document.createElement("td"));
        tablecol.appendChild(document.createTextNode(this.shortDayNames[(col + this.firstDayOfWeek) % 7]));
        tablecol.setAttribute("width", "14.2%");
        this.changeStyle(tablecol, this.styleDayName);
    }
    //build month
    //get previous days
    while (this.currentDate.getDay() != this.firstDayOfWeek) {
        this.currentDate.setDate(this.currentDate.getDate() - 1);
    }

    //loop through rows and cols
    for (row = 0; row < 6; row++) {//For each week
        tablerow = tbody.appendChild(document.createElement("tr"));
        for (col = 0; col < 7; col++) {//For each weekday
            tablecol = tablerow.appendChild(document.createElement("td"));
            // if date is for the current rendering month
            if (this.currentDate.getMonth() == this.lastMonth) {
                if (this.isSpecial(this.currentDate)) { // if date is special
                    specialDateUrl = this.specialDatesUrls[(new Date(this.currentDate.getFullYear(), this.currentDate.getMonth(), this.currentDate.getDate(), 0, 0, 0, 0, 0)).valueOf()];
                    // if specialdateurl is undefined, then check recurring date:
                    if (typeof specialDateUrl == "undefined") {
                        specialDateUrl = this.specialDatesUrls[(new Date(-1, this.currentDate.getMonth(), this.currentDate.getDate(), 0, 0, 0, 0, 0)).valueOf()];
                    }
                    if (specialDateUrl != "") { // add extra URL node if need to
                        tablecol.appendChild(document.createElement("a"));
                        tablecol.firstChild.setAttribute("href", specialDateUrl);
                        tablecol.firstChild.appendChild(document.createTextNode(this.currentDate.getDate()));
                    }
                    else { // simply add a date
                        tablecol.appendChild(document.createTextNode(this.currentDate.getDate()));
                    }
                    this.setDateOriginalState(tablecol, this.currentDate, true, true);
                }
                else {
                    // any other date
                    var exp = null;
                    if (this.enabledDateExpression != null) {
                        exp = this.enabledDateExpression;
                    }
                    tablecol.appendChild(document.createTextNode(this.currentDate.getDate()));
                    if (this.enabledDateExpression != null && !eval(exp)) {  // if enabled date expression is false, then disabled the date
                        this.changeStyle(tablecol, this.styleDayDisabled);
                        this.SetMouseOverEvent(tablecol, false, this.currentDate, this.styleDayDisabled, this.styleDayDisabledOver);
                    }
                    else {
                        this.setDateOriginalState(tablecol, this.currentDate, false, true);
                    }
                }
            }
            else {
                if (this.showOtherMonthDays) { // if other month and must show its days
                    tablecol.appendChild(document.createTextNode(this.currentDate.getDate()));
                }
                else { // other month and shouldn't show its days
                    tablecol.appendChild(document.createTextNode("\u00a0"));
                }
                this.changeStyle(tablecol, this.styleDayDisabled);
                this.SetMouseOverEvent(tablecol, false, this.currentDate, this.styleDayDisabled, this.styleDayDisabledOver);
            }
            this.currentDate.setDate(this.currentDate.getDate() + 1);
        }
    }
    this.currentDate = null;
    data = null;
    tablecol = null;
    tablerow = null;
    tbody = null;
    return table;
};


//Clear all selection.
oboutCalendar.prototype.Clear = 
function() {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    if (this.selectedDate == null) return;
    
    this.deselectDate(this.selectedDate);
    
    this.setTime(0, 0, 0);
    this.selectedDate = null;
    this.selectedCell = null;
    if(this.textbox != null) {
        this.textbox.value = "";
    }
    if(this.hiddenField != null) {
        this.incrementMonth(-this.rows*this.cols+1);
        this.hiddenField.value = "0;"+this.lastYear+"."+(this.lastMonth+1)+".1";
        this.incrementMonth(this.rows*this.cols-1);
    }
    
    this.setHiddenFieldSD(true);
}

oboutCalendar.prototype.deselectDate =
function(data) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    var obj = this.selectedCell;
    if(this.isSpecial(data)) { // special date
        this.changeStyle(obj, this.getSpecialDateStyle(data));
		obj.setAttribute("title", this.getToolTip(data));
		this.SetMouseOverEvent(obj, false, data, this.getSpecialDateStyle(data), this.getSpecialDateStyleOver(data));
	}
	else if(this.compareDates(this.dateToday, data) == 0) { //today
	    this.changeStyle(obj, this.styleDayToday);
	    this.SetMouseOverEvent(obj, false, data, this.styleDayToday, this.styleDayTodayOver);
	}
	else { // regular date
		this.changeStyle(obj, this.styleDay);
		this.SetMouseOverEvent(obj, false, data, this.styleDay, this.styleDayOver);
	}
}

oboutCalendar.prototype.SetMouseOverEvent =
function (obj, empty, data, style, styleOver) {
    if (empty) {
        obj.onmouseover = new Function();
        obj.onmouseout = new Function();
    }
    else {
        var dataString = "";
        try {
            dataString = data.toString().replace(/['"\n\r]+/g, "");
        } catch (ex) {
        }
        try {
            obj.onmouseover = new Function(this.id + ".MouseOverEvent(this, '" + styleOver + "', '" + dataString + "')");
            obj.onmouseout = new Function(this.id + ".MouseOutEvent(this, '" + style + "', '" + dataString + "')");
        } catch (ex) {
            if (!this.__wasDebugAlert__) {
                this.__wasDebugAlert__ = true;
                alert("Date caused the error: " + dataString);
            }
        }
    }
}

oboutCalendar.prototype.MouseOverEvent = 
function(obj, className, data) {
    obj.className = className;
    if(this.onClientDateMouseOver!=null) {this.onClientDateMouseOver(this, data);};
}

oboutCalendar.prototype.MouseOutEvent = 
function(obj, className, data) {
    obj.className = className;
    if(this.onClientDateMouseOut!=null) {this.onClientDateMouseOut(this, data);};
}

oboutCalendar.prototype.MonthScrollLeftEvent = 
function() {
    if(this.onClientMonthScrollLeft!=null) {this.onClientMonthScrollLeft(this);};
}

oboutCalendar.prototype.MonthScrollRightEvent = 
function() {
    if(this.onClientMonthScrollRight!=null) {this.onClientMonthScrollRight(this);};
}

oboutCalendar.prototype.SwitchViewEvent = 
function() {
    if(this.onClientSwitchView!=null) {this.onClientSwitchView(this);};
}

oboutCalendar.prototype.selectDate =
function(obj, data) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    /* if time picker exists then set the time to the data variable - selected date */
    this.updSD(data);

	if(!this.didOnceOnSelect) {
		if(this.startDateCalendarId != null && this.startDateCalendar == null) { // try to find the calendar for starting date
			this.startDateCalendar = eval("if(typeof("+this.startDateCalendarId+")==\"undefined\") null; else "+this.startDateCalendarId+";");
			if(this.startDateCalendar != null) {
				this.startDateCalendar.endDateCalendar = this;
			}
		}
		else if(this.endDateCalendar == null) { // if this is a start date calendar, then look for end date variable
			this.endDateCalendar = eval("if(typeof("+this.id+"endDate)==\"undefined\") null; else "+this.id+"endDate;");
			if(this.endDateCalendar != null) {
				this.endDateCalendar.startDateCalendar = this;
			}
		}
		this.didOnceOnSelect = true;
	}
	if(this.isSelected(data, true)) { // if selected, then deselect
		if(this.allowDeselect) {
		    if (this.multiSelectedDates)
		    {
		        // if multi selected dates is available then remove the date from the array
		        for(selDatesIndex=0;selDatesIndex<this.selectedDates.length;selDatesIndex++)
		        {
		            if (this.compareDates(data, this.selectedDates[selDatesIndex]) == 0)
		            {
		                this.selectedDates.splice(selDatesIndex, 1);
		                break;
                    }
		        }
		    }
		    this.setTime(0, 0, 0);
			this.selectedDate = null;
			this.selectedCell = null;
			if(this.textbox != null) {
				this.textbox.value = "";
			}
			if(this.hiddenField != null) {
				this.incrementMonth(-this.rows*this.cols+1);
				this.hiddenField.value = "0;"+this.lastYear+"."+(this.lastMonth+1)+".1";
				this.incrementMonth(this.rows*this.cols-1);
			}
			
			this.setHiddenFieldSD();
			
			this.setDateOriginalState(obj, data, null);
			
			// set the mouse over/out styles specific to this date (can be regular, today or special)
			if(this.isSpecial(data)) { // special date
		        this.SetMouseOverEvent(obj, false, data, this.getSpecialDateStyle(data), this.getSpecialDateStyleOver(data));
	        }
	        else if(this.compareDates(this.dateToday, data) == 0) { //today
	            this.SetMouseOverEvent(obj, false, data, this.styleDayToday, this.styleDayTodayOver);
	        }
	        else { // regular date
		        this.SetMouseOverEvent(obj, false, data, this.styleDay, this.styleDayOver);
	        }
		}
	}
	else { // clicked date is not selected
		//deselect other day if it was selected
		//if multiselecteddates is true, then don't deselect the other day
		if(this.selectedCell != null && !this.multiSelectedDates) {
			var oldObj = this.selectedCell;
			var oldData = this.selectedDate;
			this.selectedCell = null;
			this.selectedDate = null;
			this.setDateOriginalState(oldObj, oldData, null);
		}
		//select new day
		this.selectedDate = data;
		if (this.multiSelectedDates) 
		{
		    this.selectedDates[this.selectedDates.length] = data;
        }
		this.setDateOriginalState(obj, data, null);
		this.SetMouseOverEvent(obj, false, data, this.styleDaySelected, this.styleDaySelectedOver);
		
		// switch other calendar view
		if(this.startDateCalendar != null) {
			//check if other calendar has a selected date and if it is greater 
			//than this calendar selected date.  If it is, then need to change it.
			if(this.startDateCalendar.selectedDate == null || (this.startDateCalendar.selectedDate != null && this.compareDates(this.startDateCalendar.selectedDate, data) > 0)) {
				this.startDateCalendar.updateYearSelector(data.getFullYear());
				this.startDateCalendar.updateMonthSelector(data.getMonth());
				this.startDateCalendar.addToQueue(this.startDateCalendar.id + "." + (("switchView")) + "(new Date(" + data.getFullYear() + "," + data.getMonth() + "," + data.getDate() + ",9,0,0,999), new Date(" + data.getFullYear() + "," + data.getMonth() + "," + data.getDate() + ",9,0,0,999), false);");
			}
		}
		else if(this.endDateCalendar != null) {
			if(this.endDateCalendar.selectedDate == null || (this.endDateCalendar.selectedDate != null && this.compareDates(this.endDateCalendar.selectedDate, data) < 0)) {
				this.endDateCalendar.updateYearSelector(data.getFullYear());
				this.endDateCalendar.updateMonthSelector(data.getMonth());
				this.endDateCalendar.addToQueue(this.endDateCalendar.id + "." + (("switchView")) + "(new Date(" + data.getFullYear() + "," + data.getMonth() + "," + data.getDate() + ",9,0,0,999), new Date(" + data.getFullYear() + "," + data.getMonth() + "," + data.getDate() + ",9,0,0,999), true);");
				
			}
		}
		//populate hidden field
		if(this.hiddenField != null) {
		    // add also the selected time
	        var time = this.getTime();
	        var timeString = "";
	        if (time != null)    
	            timeString = ";" + time["Hour"] + "." + time["Minute"] + "." + time["Second"];
			this.incrementMonth(-this.rows*this.cols+1);
			this.hiddenField.value = data.getFullYear()+"."+(data.getMonth()+1)+"."+data.getDate()+";"+this.lastYear+"."+(this.lastMonth+1)+".1" + timeString;
			this.incrementMonth(this.rows*this.cols-1);
		}
		
		this.setHiddenFieldSD();
	}
	
	// if in datepicker mode, then close calendar
	if(this.datePickerMode) {
		// close calendar
		var ev = null;
		if(document.createEvent) {
			ev = document.createEvent("HTMLEvents");
			ev.initEvent("click", true, false);
		}
		this.displayCalendar(ev);
	}
	
	// modify the selectedDate value
	// if the time picker is used, add hours, minutes, seconds to the date
	this.updSD(null);
	
	if(this.onClientDateChanged!=null) {this.onClientDateChanged(this, this.selectedDate);};
	if(this.postBackCode!=null) {eval(this.postBackCode);};
};

oboutCalendar.prototype.setDateOriginalState =
function(obj, data, isSpecial, isBuild) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();

    // modify the data value
    // if the time picker is used, add hours, minutes, seconds to the date
    this.updSD(data, null, isBuild);

    var selectable = true;
    if (this.isSelected(data, isBuild ? false : true)) { //if date is selected
        this.selectedCell = obj;
        // set the selected date's year into the year selector
        if (!isBuild) {
            this.updateYearSelector(data.getFullYear());
            this.updateMonthSelector(data.getMonth());
        }
        this.changeStyle(obj, this.styleDaySelected);
        this.SetMouseOverEvent(obj, false, data, this.styleDaySelected, this.styleDaySelectedOver);
        // ???
        if (this.textbox != null/* && !isBuild*/) {
            // on date selection if time selection doesn't exists set the current time
            if (!this.timeSelector) {
                var currDate = new Date();

                data.setHours(currDate.getHours());
                data.setMinutes(currDate.getMinutes());
                data.setSeconds(currDate.getSeconds());
            }
            else //get the time from the selector
            {
                var time = this.getTime();
                if (time != null) {
                    data.setHours(time["Hour"]);
                    data.setMinutes(time["Minute"]);
                    data.setSeconds(time["Second"]);
                }
            }
            this.textbox.value = this.formatDate(data, this.dateFormat);
        }
    }
    else if ((isSpecial != null && isSpecial) || this.isSpecial(data)) {
        this.changeStyle(obj, this.getSpecialDateStyle(data));
        obj.setAttribute("title", this.getToolTip(data));
        selectable = this.allowSelectSpecial;
        this.SetMouseOverEvent(obj, false, data, this.getSpecialDateStyle(data), this.getSpecialDateStyleOver(data));
    }
    else if ((this.dateMin != null && this.compareDates(data, this.dateMin) < 0)
	|| (this.dateMax != null && this.compareDates(data, this.dateMax) > 0)) { // if date is outside datemin-datemax range
        this.changeStyle(obj, this.styleDayDisabled);
        selectable = false;
        this.SetMouseOverEvent(obj, false, data, this.styleDayDisabled, this.styleDayDisabledOver);
    }
    else if (this.compareDates(this.dateToday, data) == 0) { //today
        this.changeStyle(obj, this.styleDayToday);
        selectable = this.allowSelectRegular;
        this.SetMouseOverEvent(obj, false, data, this.styleDayToday, this.styleDayTodayOver);
    }
    else { // regular date
        this.changeStyle(obj, this.styleDay);
        selectable = this.allowSelectRegular;
        this.SetMouseOverEvent(obj, false, data, this.styleDay, this.styleDayOver);
    }
    if (selectable) {
        if (obj.addEventListener) {            
            var fnc = this.id + "." + "selectDate" + "(this, new Date(" + data.getFullYear() + "," 
                    + data.getMonth() + "," + data.getDate() + ",9,0,0,999));";
            var newclick = eval("(function(){" + fnc + "});");
            obj.onclick = newclick;            
        }
        else {
            obj.onclick = new Function(this.id + "." + "selectDate" + "(this, new Date(" + data.getFullYear() + "," + data.getMonth() + "," + data.getDate() + ",9,0,0,999))");
        }
    }
    else {
        obj.onclick = null;
    }
};

oboutCalendar.prototype.hideHTMLLists =
function() {
    // hide year,month,hour,minute,second selectors
	if (document.getElementById(this.id + "_YearSelectorContainer")) this.displayYearSelector("none");
	if (document.getElementById(this.id + "_MonthSelectorContainer")) this.displayMonthSelector("none");
	
	if (document.getElementById(this.id + "_HourSelectorContainer")) this.displayHourSelector("none");
	if (document.getElementById(this.id + "_MinuteSelectorContainer")) this.displayMinuteSelector("none");
	if (document.getElementById(this.id + "_SecondSelectorContainer")) this.displaySecondSelector("none");
}

oboutCalendar.prototype.displayCalendar =
function(e) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();

    if (!e) { e = window.event; };
    e.cancelBubble = true;
    if (e.stopPropagation) {
        e.stopPropagation();
    }

    if (this.isVisible || !this.enabled) { //hide if visible
        this.calendarContainer.style.display = "none";
        this.iframe.style.display = "none";
        this.isVisible = false;
        document.oboutOpenCalendar = null;

        // hide year,month,hour,minute,second selectors
        this.hideHTMLLists();

        return;
    }

    var useScroll = true;
    var mouseX, mouseY;
    if (window.event && !this.isSafari) {
        mouseX = window.event.clientX;
        mouseY = window.event.clientY;
    }
    else {
        useScroll = false;
        mouseX = e.pageX;
        mouseY = e.pageY;
    }

    // hide an open calendar
    if (document.oboutOpenCalendar != null) {
        var ev = null;
        if (document.createEvent) {
            ev = document.createEvent("HTMLEvents");
            ev.initEvent("click", true, false);
        }
        document.oboutOpenCalendar.displayCalendar(ev);
    }
    if (this.calendarContainer.parentNode.nodeName.toLowerCase() != "body") {
        document.body.appendChild(this.calendarContainer.parentNode.removeChild(this.calendarContainer));
        document.body.appendChild(this.iframe.parentNode.removeChild(this.iframe));
    }

    this.calendarContainer.style.position = "absolute";
    this.calendarContainer.style.display = "block";
    this.calendarContainer.style.zIndex = "10001";
    if (this.isIE) { //show the iframe in IE only
        this.iframe.style.zIndex = "10000";
        this.iframe.style.height = this.calendarContainer.offsetHeight + "px";
        this.iframe.style.width = this.calendarContainer.offsetWidth + "px";
        this.iframe.style.display = "block";
    }

    var cWidth = (document.documentElement && document.documentElement.clientWidth && this.isIE) ? document.documentElement.clientWidth : document.body.clientWidth;
    var cHeight = (document.documentElement && document.documentElement.clientHeight && this.isIE) ? document.documentElement.clientHeight : document.body.clientHeight;
    var scrollY = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
    var scrollX = (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;


    var leftPos;
    var topPos;

    if (this.textbox == null || this.Align != "Cursor") {
        leftPos = mouseX + ((useScroll) ? scrollX : 0) - this.calendarContainer.offsetWidth + this.offsetLeft;
        // now check if right edge is not outside the boundary of screen
        if (leftPos + this.calendarContainer.offsetWidth - scrollX > cWidth) {
            leftPos = mouseX + ((useScroll) ? scrollX : 0) - this.calendarContainer.offsetWidth;
        }
        // now check if left edge is less than 0 or outside the boundary of window
        if (leftPos < 0 || leftPos - scrollX < 0) {
            leftPos = scrollX;
        }

        var topPos = mouseY + ((useScroll) ? scrollY : 0) + this.offsetTop;
        // check if bottom edge is not outside the boundary of screen
        if (topPos + this.calendarContainer.offsetHeight - scrollY > cHeight) {
            topPos = mouseY + ((useScroll) ? scrollY : 0) - this.calendarContainer.offsetHeight;
        }
        // now check if top edge is less than 0 or outside the boundary of window
        if (topPos < 0 || topPos - scrollY < 0) {
            topPos = scrollY;
        }
    }
    else {
        leftPos = this.findPosX(this.textbox);
        if (leftPos + this.calendarContainer.offsetWidth > cWidth) {
            leftPos = this.findPosX(this.textbox) + this.textbox.offsetWidth - this.calendarContainer.offsetWidth;
        }
        
        if (leftPos < 0) {
            leftPos = this.findPosX(this.textbox);
        }

        var topPos = this.findPosY(this.textbox) + this.textbox.offsetHeight;
        // check if bottom edge is not outside the boundary of screen
        if (topPos + this.calendarContainer.offsetHeight > cHeight) {

            topPos = this.findPosY(this.textbox) - this.calendarContainer.offsetHeight;
        }
        // now check if top edge is less than 0 or outside the boundary of window
        if (topPos < 0) {
            topPos = 0;
        }
    }
    //	var leftPos = this.getLeft(this.button) + this.button.offsetWidth - this.calendarContainer.offsetWidth + this.offsetLeft;
    //	leftPos = (leftPos<0)?0:leftPos;
    //	leftPos = (leftPos+this.calendarContainer.offsetWidth>document.body.offsetWidth)?document.body.offsetWidth - this.calendarContainer.offsetWidth:leftPos;
    //	var topPos = this.getTop(this.button) + this.button.offsetHeight + this.offsetTop;

    if (this.Align != "Cursor") {
        if (typeof this.button == "object") {
            var elementCoords = this.GetElementCoords(this.button);
            var calendarCoords = this.GetCalendarCoordsFromElement(elementCoords, cHeight, scrollY, cWidth, scrollX);

            topPos = calendarCoords["top"];
            leftPos = calendarCoords["left"];
        }
    }

    ///////////////////
    this.calendarContainer.style.top = topPos + "px";
    this.calendarContainer.style.left = leftPos + "px";
    if (this.isIE) {
        this.iframe.style.top = topPos + "px";
        this.iframe.style.left = leftPos + "px";
    }
    document.oboutOpenCalendar = this;
    eval("document.onclick = function(e){if(document.oboutOpenCalendar){document.oboutOpenCalendar." + (("displayCalendar")) + "(e);}}");

    this.isVisible = true;
};

// get the Calendar coords related to the element coords (element the Calendar it's attached to)
oboutCalendar.prototype.GetCalendarCoordsFromElement =
function (elementCoords, cHeight, scrollY, cWidth, scrollX) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    var menuLeft = 0;
    var menuTop = 0;
    
    switch(this.Align)
    {
        case 'Under':
            menuLeft = elementCoords['left'];
            menuTop = elementCoords['bottom'];
            break;
            
        case 'Above':
            menuLeft = elementCoords['left'];
            menuTop = elementCoords['bottom'] - this.calendarContainer.offsetHeight - this.button.offsetHeight;
            break;
            
        case 'Right':
            menuLeft = elementCoords['right'];
            menuTop = elementCoords['top'];
            break;
            
        case 'Left':
            menuLeft = elementCoords['right'] - this.calendarContainer.offsetWidth - this.button.offsetWidth;
            menuTop = elementCoords['top'];
            break;
    }
    
    // now check if right edge is not outside the boundary of screen
    if(menuLeft + this.calendarContainer.offsetWidth - scrollX > cWidth) {
        menuLeft = cWidth - this.calendarContainer.offsetWidth + scrollX;
    }
    // now check if left edge is less than 0 or outside the boundary of window
    if(menuLeft < 0 || menuLeft - scrollX < 0) {
        menuLeft = scrollX;
    }

    // check if bottom edge is not outside the boundary of screen
    if(menuTop + this.calendarContainer.offsetHeight - scrollY > cHeight) {
        menuTop = cHeight - this.calendarContainer.offsetHeight + scrollY;
    }
    // now check if top edge is less than 0 or outside the boundary of window
    if(menuTop < 0 || menuTop - scrollY < 0) {
        menuTop = scrollY;
    }
    
    return {'left' : menuLeft, 'top' : menuTop};
}

// get the coords of the element the Calendar it's attached to
oboutCalendar.prototype.GetElementCoords =
function(element, coordLeft, coordTop, coordRight, coordBottom) {   
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
	if (typeof element == 'undefined' || element == null) 
		return {'left' : 0, 'top' : 0, 'right' : 0, 'bottom' : 0};

	if (coordLeft == null) coordLeft = this.getLeft(element);
	if (coordTop == null) coordTop = this.getTop(element);
	if (coordRight == null) coordRight = coordLeft + element.offsetWidth;
	if (coordBottom == null) coordBottom = coordTop + element.offsetHeight;

	return {'left' : coordLeft, 'top' : coordTop, 'right' : coordRight, 'bottom' : coordBottom};
}

oboutCalendar.prototype.setHourSelectorOverEffect =
function(element, cssClass) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    if (document.getElementById(this.id + "_HourSelectorContainer").style.display != 'none')
        this.changeStyle(element, cssClass);
}

oboutCalendar.prototype.setMinuteSelectorOverEffect =
function(element, cssClass) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    if (document.getElementById(this.id + "_MinuteSelectorContainer").style.display != 'none')
        this.changeStyle(element, cssClass);
}

oboutCalendar.prototype.setSecondSelectorOverEffect =
function(element, cssClass) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    if (document.getElementById(this.id + "_SecondSelectorContainer").style.display != 'none')
        this.changeStyle(element, cssClass);
}

oboutCalendar.prototype.hourSelectorScrollerTimer;
oboutCalendar.prototype.hourSelectorAutomatMoverTriggered;

oboutCalendar.prototype.hourSelectorMoveDownScroll =
function(eventType) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    if (eventType=="start")
    {
        this.hourSelectorScrollerTimer = setTimeout(this.id + ".hourSelectorMoveDown(true)", this.firstHourSelectorScrollSpeed);
        this.hourSelectorAutomatMoverTriggered = true;
    }
    if (eventType=="end")
    {
        clearTimeout(this.hourSelectorScrollerTimer);
    }
}

oboutCalendar.prototype.hourSelectorMoveUpScroll =
function(eventType) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    if (eventType=="start")
    {
        this.hourSelectorScrollerTimer = setTimeout(this.id + ".hourSelectorMoveUp(true)", this.firstHourSelectorScrollSpeed);
        this.hourSelectorAutomatMoverTriggered = true;
    }
    if (eventType=="end")
    {
        clearTimeout(this.hourSelectorScrollerTimer);
    }
}

oboutCalendar.prototype.hourSelectorMoveDown =
function(timer) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    if (timer) 
        this.hourSelectorScrollerTimer = setTimeout(this.id + ".hourSelectorMoveDown(true)", this.hourSelectorScrollSpeed);
    else
    { 
        if (this.hourSelectorAutomatMoverTriggered)
        {
            this.hourSelectorAutomatMoverTriggered = false;
            this.isWorking = false;
            return;
        }
    }
    var HourSelectorContainer = document.getElementById(this.id + "_HourSelectorContainer");
    var containers = HourSelectorContainer.childNodes[0].childNodes;
    var firstHour = true;
    var lastHour = true;
    var hoursDisplayed = 0;
    for (var index = 0; index < containers.length; index++)
    {
        var hour = containers[index].getAttribute("hour");
        if (hour != null && document.getElementById(this.id + "_Hour" + hour).style.display != 'none') hoursDisplayed++;
    }
    
    var hourHidden = false;
    for (var index = 0; index < containers.length; index++)
    {
        var hour = containers[index].getAttribute("hour");
        if (hour != null) hour = parseInt(hour, 10);
        
        if (hour != null)
        {
            // this is the first hour - move up
            if (document.getElementById(this.id + "_Hour" + hour) && 
                document.getElementById(this.id + "_Hour" + hour).style.display != 'none' &&
                document.getElementById(this.id + "_Hour" + (hour + hoursDisplayed)))
            {
                document.getElementById(this.id + "_Hour" + hour).style.display = "none";
                hourHidden = true;
            }
            
            // this is the first hour - move up
            if (hourHidden && document.getElementById(this.id + "_Hour" + (hour + hoursDisplayed)))
            {
                document.getElementById(this.id + "_Hour" + (hour + hoursDisplayed)).style.display = "";
                
                break;
            }
        }
    }
    
    this.isWorking = false;
}

oboutCalendar.prototype.hourSelectorMoveUp =
function(timer) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    if (timer) this.hourSelectorScrollerTimer = setTimeout(this.id + ".hourSelectorMoveUp(true)", this.hourSelectorScrollSpeed);
    else
    { 
        if (this.hourSelectorAutomatMoverTriggered)
        {
            this.hourSelectorAutomatMoverTriggered = false;
            this.isWorking = false;
            return;
        }
    }
    
    var HourSelectorContainer = document.getElementById(this.id + "_HourSelectorContainer");
    var containers = HourSelectorContainer.childNodes[0].childNodes;
    var firstHour = true;
    var lastHour = true;
    var hoursDisplayed = 0;
    for (var index = 0; index < containers.length; index++)
    {
        var hour = containers[index].getAttribute("hour");
        if (hour != null && document.getElementById(this.id + "_Hour" + hour).style.display != 'none') hoursDisplayed++;
    }
    
    var hourHidden = false;
    for (var index = 0; index < containers.length; index++)
    {
        var hour = containers[index].getAttribute("hour");
        if (hour != null) hour = parseInt(hour, 10);
        
        if (hour != null)
        {
            // this is the first hour - move up
            if (document.getElementById(this.id + "_Hour" + hour) && 
                document.getElementById(this.id + "_Hour" + hour).style.display != 'none' &&
                document.getElementById(this.id + "_Hour" + (hour - 1)) &&
                document.getElementById(this.id + "_Hour" + (hour + hoursDisplayed - 1)))
            {
                document.getElementById(this.id + "_Hour" + (hour - 1)).style.display = "";
                hourHidden = true;
            }
            
            // this is the first hour - move up
            if (hourHidden && document.getElementById(this.id + "_Hour" + (hour + hoursDisplayed - 1)))
            {
                document.getElementById(this.id + "_Hour" + (hour + hoursDisplayed - 1)).style.display = "none";
                
                break;
            }
        }
    }
    
    this.isWorking = false;
}

oboutCalendar.prototype.minuteSelectorScrollerTimer;
oboutCalendar.prototype.minuteSelectorAutomatMoverTriggered;

oboutCalendar.prototype.minuteSelectorMoveDownScroll =
function(eventType) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    if (eventType=="start")
    {
        this.minuteSelectorScrollerTimer = setTimeout(this.id + ".minuteSelectorMoveDown(true)", this.firstMinuteSelectorScrollSpeed);
        this.minuteSelectorAutomatMoverTriggered = true;
    }
    if (eventType=="end")
    {
        clearTimeout(this.minuteSelectorScrollerTimer);
    }
}

oboutCalendar.prototype.minuteSelectorMoveUpScroll =
function(eventType) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    if (eventType=="start")
    {
        this.minuteSelectorScrollerTimer = setTimeout(this.id + ".minuteSelectorMoveUp(true)", this.firstMinuteSelectorScrollSpeed);
        this.minuteSelectorAutomatMoverTriggered = true;
    }
    if (eventType=="end")
    {
        clearTimeout(this.minuteSelectorScrollerTimer);
    }
}

oboutCalendar.prototype.minuteSelectorMoveDown =
function(timer) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    if (timer) 
        this.minuteSelectorScrollerTimer = setTimeout(this.id + ".minuteSelectorMoveDown(true)", this.minuteSelectorScrollSpeed);
    else
    { 
        if (this.minuteSelectorAutomatMoverTriggered)
        {
            this.minuteSelectorAutomatMoverTriggered = false;
            this.isWorking = false;
            return;
        }
    }
    var MinuteSelectorContainer = document.getElementById(this.id + "_MinuteSelectorContainer");
    var containers = MinuteSelectorContainer.childNodes[0].childNodes;
    var firstMinute = true;
    var lastMinute = true;
    var minutesDisplayed = 0;
    for (var index = 0; index < containers.length; index++)
    {
        var minute = containers[index].getAttribute("minute");
        if (minute != null && document.getElementById(this.id + "_Minute" + minute).style.display != 'none') minutesDisplayed++;
    }
    
    var minuteHidden = false;
    for (var index = 0; index < containers.length; index++)
    {
        var minute = containers[index].getAttribute("minute");
        if (minute != null) minute = parseInt(minute, 10);
        
        if (minute != null)
        {
            // this is the first minute - move up
            if (document.getElementById(this.id + "_Minute" + minute) && 
                document.getElementById(this.id + "_Minute" + minute).style.display != 'none' &&
                document.getElementById(this.id + "_Minute" + (minute + (minutesDisplayed))))
            {
                document.getElementById(this.id + "_Minute" + minute).style.display = "none";
                minuteHidden = true;
            }
            
            // this is the first minute - move up
            if (minuteHidden && document.getElementById(this.id + "_Minute" + (minute + (minutesDisplayed))))
            {
                document.getElementById(this.id + "_Minute" + (minute + (minutesDisplayed))).style.display = "";
                
                break;
            }
        }
    }
    
    this.isWorking = false;
}

oboutCalendar.prototype.minuteSelectorMoveUp =
function(timer) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    if (timer) this.minuteSelectorScrollerTimer = setTimeout(this.id + ".minuteSelectorMoveUp(true)", this.minuteSelectorScrollSpeed);
    else
    { 
        if (this.minuteSelectorAutomatMoverTriggered)
        {
            this.minuteSelectorAutomatMoverTriggered = false;
            this.isWorking = false;
            return;
        }
    }
    
    var MinuteSelectorContainer = document.getElementById(this.id + "_MinuteSelectorContainer");
    var containers = MinuteSelectorContainer.childNodes[0].childNodes;
    var firstMinute = true;
    var lastMinute = true;
    var minutesDisplayed = 0;
    for (var index = 0; index < containers.length; index++)
    {
        var minute = containers[index].getAttribute("minute");
        if (minute != null && document.getElementById(this.id + "_Minute" + minute).style.display != 'none') minutesDisplayed++;
    }
    
    var minuteHidden = false;
    for (var index = 0; index < containers.length; index++)
    {
        var minute = containers[index].getAttribute("minute");
        if (minute != null) minute = parseInt(minute, 10);
        
        if (minute != null)
        {
            // this is the first minute - move up
            if (document.getElementById(this.id + "_Minute" + minute) && 
                document.getElementById(this.id + "_Minute" + minute).style.display != 'none' &&
                document.getElementById(this.id + "_Minute" + (minute - 1)) &&
                document.getElementById(this.id + "_Minute" + (minute + minutesDisplayed - 1)))
            {
                document.getElementById(this.id + "_Minute" + (minute - 1)).style.display = "";
                minuteHidden = true;
            }
            
            // this is the first minute - move up
            if (minuteHidden && document.getElementById(this.id + "_Minute" + (minute + minutesDisplayed - 1)))
            {
                document.getElementById(this.id + "_Minute" + (minute + minutesDisplayed - 1)).style.display = "none";
                
                break;
            }
        }
    }
    
    this.isWorking = false;
}

oboutCalendar.prototype.secondSelectorScrollerTimer;
oboutCalendar.prototype.secondSelectorAutomatMoverTriggered;

oboutCalendar.prototype.secondSelectorMoveDownScroll =
function(eventType) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    if (eventType=="start")
    {
        this.secondSelectorScrollerTimer = setTimeout(this.id + ".secondSelectorMoveDown(true)", this.firstSecondSelectorScrollSpeed);
        this.secondSelectorAutomatMoverTriggered = true;
    }
    if (eventType=="end")
    {
        clearTimeout(this.secondSelectorScrollerTimer);
    }
}

oboutCalendar.prototype.secondSelectorMoveUpScroll =
function(eventType) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    if (eventType=="start")
    {
        this.secondSelectorScrollerTimer = setTimeout(this.id + ".secondSelectorMoveUp(true)", this.firstSecondSelectorScrollSpeed);
        this.secondSelectorAutomatMoverTriggered = true;
    }
    if (eventType=="end")
    {
        clearTimeout(this.secondSelectorScrollerTimer);
    }
}

oboutCalendar.prototype.secondSelectorMoveDown =
function(timer) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    if (timer) 
        this.secondSelectorScrollerTimer = setTimeout(this.id + ".secondSelectorMoveDown(true)", this.secondSelectorScrollSpeed);
    else
    { 
        if (this.secondSelectorAutomatMoverTriggered)
        {
            this.secondSelectorAutomatMoverTriggered = false;
            this.isWorking = false;
            return;
        }
    }
    var SecondSelectorContainer = document.getElementById(this.id + "_SecondSelectorContainer");
    var containers = SecondSelectorContainer.childNodes[0].childNodes;
    var firstSecond = true;
    var lastSecond = true;
    var secondsDisplayed = 0;
    for (var index = 0; index < containers.length; index++)
    {
        var second = containers[index].getAttribute("second");
        if (second != null && document.getElementById(this.id + "_Second" + second).style.display != 'none') secondsDisplayed++;
    }
    
    var secondHidden = false;
    for (var index = 0; index < containers.length; index++)
    {
        var second = containers[index].getAttribute("second");
        if (second != null) second = parseInt(second, 10);
        
        if (second != null)
        {
            // this is the first second - move up
            if (document.getElementById(this.id + "_Second" + second) && 
                document.getElementById(this.id + "_Second" + second).style.display != 'none' &&
                document.getElementById(this.id + "_Second" + (second + secondsDisplayed)))
            {
                document.getElementById(this.id + "_Second" + second).style.display = "none";
                secondHidden = true;
            }
            
            // this is the first second - move up
            if (secondHidden && document.getElementById(this.id + "_Second" + (second + secondsDisplayed)))
            {
                document.getElementById(this.id + "_Second" + (second + secondsDisplayed)).style.display = "";
                
                break;
            }
        }
    }
    
    this.isWorking = false;
}

oboutCalendar.prototype.secondSelectorMoveUp =
function(timer) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    if (timer) this.secondSelectorScrollerTimer = setTimeout(this.id + ".secondSelectorMoveUp(true)", this.secondSelectorScrollSpeed);
    else
    { 
        if (this.secondSelectorAutomatMoverTriggered)
        {
            this.secondSelectorAutomatMoverTriggered = false;
            this.isWorking = false;
            return;
        }
    }
    
    var SecondSelectorContainer = document.getElementById(this.id + "_SecondSelectorContainer");
    var containers = SecondSelectorContainer.childNodes[0].childNodes;
    var firstSecond = true;
    var lastSecond = true;
    var secondsDisplayed = 0;
    for (var index = 0; index < containers.length; index++)
    {
        var second = containers[index].getAttribute("second");
        if (second != null && document.getElementById(this.id + "_Second" + second).style.display != 'none') secondsDisplayed++;
    }
    
    var secondHidden = false;
    for (var index = 0; index < containers.length; index++)
    {
        var second = containers[index].getAttribute("second");
        if (second != null) second = parseInt(second, 10);
        
        if (second != null)
        {
            // this is the first second - move up
            if (document.getElementById(this.id + "_Second" + second) && 
                document.getElementById(this.id + "_Second" + second).style.display != 'none' &&
                document.getElementById(this.id + "_Second" + (second - 1)) &&
                document.getElementById(this.id + "_Second" + (second + secondsDisplayed - 1)))
            {
                document.getElementById(this.id + "_Second" + (second - 1)).style.display = "";
                secondHidden = true;
            }
            
            // this is the first second - move up
            if (secondHidden && document.getElementById(this.id + "_Second" + (second + secondsDisplayed - 1)))
            {
                document.getElementById(this.id + "_Second" + (second + secondsDisplayed - 1)).style.display = "none";
                
                break;
            }
        }
    }
    
    this.isWorking = false;
}

oboutCalendar.prototype.displayHourSelector =
function(display, docEvent) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    if (display != "none")
    {
        // hide year,hour,minute,second selectors
        if (document.getElementById(this.id + "_YearSelectorContainer")) this.displayYearSelector('none');
        if (document.getElementById(this.id + "_MonthSelectorContainer")) this.displayMonthSelector('none');
        
        if (document.getElementById(this.id + "_MinuteSelectorContainer")) this.displayMinuteSelector('none');
        if (document.getElementById(this.id + "_SecondSelectorContainer")) this.displaySecondSelector('none');
    }
    
    var HourSelectorContainer = document.getElementById(this.id + "_HourSelectorContainer");
    var HourSelectorTitle = document.getElementById(this.id + "_HourSelectorTitle");
    var HourSelectorIframe = document.getElementById("_" + this.id + "_HourSelectorIframe");
    
    if (display == "none")
    {
        // hide the hour selector container
        HourSelectorContainer.style.display = "none";
        HourSelectorIframe.style.display = "none";
    }
    else
    {
        // attach the container directly to the document object
        if (document.body != HourSelectorContainer.parentNode)
            document.body.insertBefore(HourSelectorContainer, document.body.firstChild);
            
        // attach the container directly to the document object
        if (document.body != HourSelectorIframe.parentNode)
            document.body.insertBefore(HourSelectorIframe, document.body.firstChild);
            
        HourSelectorContainer.style.display = "inline";
        
        // calculate the position for the hour selector
        HourSelectorContainer.style.zIndex = "10003";
        HourSelectorContainer.style.position = "absolute";
        var left = this.findPosX(HourSelectorTitle);
        var top = this.findPosY(HourSelectorTitle) + HourSelectorTitle.offsetHeight;
        
        HourSelectorContainer.style.left = left + "px";
        HourSelectorContainer.style.top = top + "px";
        
        if(this.isIE) { //show the iframe in IE only
		    HourSelectorIframe.style.zIndex = "10002";
		    HourSelectorIframe.style.height = HourSelectorContainer.offsetHeight + "px";
		    HourSelectorIframe.style.width = HourSelectorContainer.offsetWidth + "px";
		    HourSelectorIframe.style.display = "inline";
		    HourSelectorIframe.style.position = "absolute";
	        HourSelectorIframe.style.top = top + "px";
		    HourSelectorIframe.style.left = left + "px";
	    }   
    }
    
    this.isWorking = false; 
}

oboutCalendar.prototype.displayMinuteSelector =
function(display, docEvent) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    if (display != "none")
    {
        // hide year,hour,minute,second selectors
        if (document.getElementById(this.id + "_YearSelectorContainer")) this.displayYearSelector('none');
        if (document.getElementById(this.id + "_MonthSelectorContainer")) this.displayMonthSelector('none');
        if (document.getElementById(this.id + "_HourSelectorContainer")) this.displayHourSelector('none');
        
        if (document.getElementById(this.id + "_SecondSelectorContainer")) this.displaySecondSelector('none');
    }
    
    var MinuteSelectorContainer = document.getElementById(this.id + "_MinuteSelectorContainer");
    var MinuteSelectorTitle = document.getElementById(this.id + "_MinuteSelectorTitle");
    var MinuteSelectorIframe = document.getElementById("_" + this.id + "_MinuteSelectorIframe");
    
    if (display == "none")
    {
        // hide the Minute selector container
        MinuteSelectorContainer.style.display = "none";
        MinuteSelectorIframe.style.display = "none";
    }
    else
    {
        // attach the container directly to the document object
        if (document.body != MinuteSelectorContainer.parentNode)
            document.body.insertBefore(MinuteSelectorContainer, document.body.firstChild);
            
        // attach the container directly to the document object
        if (document.body != MinuteSelectorIframe.parentNode)
            document.body.insertBefore(MinuteSelectorIframe, document.body.firstChild);
            
        MinuteSelectorContainer.style.display = "inline";
        MinuteSelectorContainer.style.zIndex = "10003";
        MinuteSelectorContainer.style.position = "absolute";
        
        // get the Minute selector title position
        var left = this.findPosX(MinuteSelectorTitle);
        var top = this.findPosY(MinuteSelectorTitle) + MinuteSelectorTitle.offsetHeight;
        
        MinuteSelectorContainer.style.left = left + "px";
        MinuteSelectorContainer.style.top = top + "px";
        
        if(this.isIE) { //show the iframe in IE only
		    MinuteSelectorIframe.style.zIndex = "10002";
		    MinuteSelectorIframe.style.height = MinuteSelectorContainer.offsetHeight + "px";
		    MinuteSelectorIframe.style.width = MinuteSelectorContainer.offsetWidth + "px";
		    MinuteSelectorIframe.style.display = "inline";
		    MinuteSelectorIframe.style.position = "absolute";
	        MinuteSelectorIframe.style.top = top + "px";
		    MinuteSelectorIframe.style.left = left + "px";
	    }    
    }
    
    this.isWorking = false; 
}

oboutCalendar.prototype.displaySecondSelector =
function(display, docEvent) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    if (display != "none")
    {
        // hide year,hour,minute,second selectors
        if (document.getElementById(this.id + "_YearSelectorContainer")) this.displayYearSelector('none');
        if (document.getElementById(this.id + "_MonthSelectorContainer")) this.displayMonthSelector('none');
        if (document.getElementById(this.id + "_HourSelectorContainer")) this.displayHourSelector('none');
        if (document.getElementById(this.id + "_MinuteSelectorContainer")) this.displayMinuteSelector('none');
        
    }
    
    var SecondSelectorContainer = document.getElementById(this.id + "_SecondSelectorContainer");
    var SecondSelectorTitle = document.getElementById(this.id + "_SecondSelectorTitle");
    var SecondSelectorIframe = document.getElementById("_" + this.id + "_SecondSelectorIframe");
    
    if (display == "none")
    {
        // hide the Second selector container
        SecondSelectorContainer.style.display = "none";
        SecondSelectorIframe.style.display = "none";
    }
    else
    {
        // attach the container directly to the document object
        if (document.body != SecondSelectorContainer.parentNode)
            document.body.insertBefore(SecondSelectorContainer, document.body.firstChild);
            
        // attach the container directly to the document object
        if (document.body != SecondSelectorIframe.parentNode)
            document.body.insertBefore(SecondSelectorIframe, document.body.firstChild);
            
        SecondSelectorContainer.style.display = "inline";
        SecondSelectorContainer.style.zIndex = "10003";
        SecondSelectorContainer.style.position = "absolute";
        
        // get the Second selector title position
        var left = this.findPosX(SecondSelectorTitle);
        var top = this.findPosY(SecondSelectorTitle) + SecondSelectorTitle.offsetHeight;
        
        SecondSelectorContainer.style.left = left + "px";
        SecondSelectorContainer.style.top = top + "px";
        
        if(this.isIE) { //show the iframe in IE only
		    SecondSelectorIframe.style.zIndex = "10002";
		    SecondSelectorIframe.style.height = SecondSelectorContainer.offsetHeight + "px";
		    SecondSelectorIframe.style.width = SecondSelectorContainer.offsetWidth + "px";
		    SecondSelectorIframe.style.display = "inline";
		    SecondSelectorIframe.style.position = "absolute";
	        SecondSelectorIframe.style.top = top + "px";
		    SecondSelectorIframe.style.left = left + "px";
	    }     
    }
    
    this.isWorking = false; 
}

// helper functions
oboutCalendar.prototype.incrementMonth =
function(number) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
	var tmp = this.lastYear * 12 + this.lastMonth + number;
	this.lastMonth = tmp%12;
	this.lastYear = Math.floor(tmp/12);
};

oboutCalendar.prototype.changeStyle =
function(tmp, clsName) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
	if(tmp != null && clsName != null) {
		tmp.className = clsName;
	}
};

oboutCalendar.prototype.addToQueue =
function(expression) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
	this.actionQueue.push(expression);
	this.checkQueue();
};
oboutCalendar.prototype.checkQueue =
function() {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
	if(!this.isWorking && this.actionQueue.length>0) {
		this.isWorking=true;
		eval(this.actionQueue.shift());
	}
};

oboutCalendar.prototype.isSpecial =
function (data) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();

    try {
        data = new Date(data.getFullYear(), data.getMonth(), data.getDate(), 0, 0, 0, 0);
        // first check nonrecurring date
        if (typeof (this.specialDates[data.valueOf()]) != "undefined") {
            return true;
        }
        data.setYear(-1); // check recurring date
        if (typeof (this.specialDates[data.valueOf()]) != "undefined") {
            return true;
        }
    } catch (ex) { }

    return false;
};

oboutCalendar.prototype.getSpecialDateStyle =
function(data) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
	data = new Date(data.getFullYear(), data.getMonth(), data.getDate(),0,0,0,0);
	if(typeof(this.specialDatesStyles[data.valueOf()]) != "undefined") {
		return this.specialDatesStyles[data.valueOf()];
	}
	data.setYear(-1);
	return this.specialDatesStyles[data.valueOf()];
};

oboutCalendar.prototype.getSpecialDateStyleOver =
function(data) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
	data = new Date(data.getFullYear(), data.getMonth(), data.getDate(),0,0,0,0);
	if(typeof(this.specialDatesStylesOver[data.valueOf()]) != "undefined") {
		return this.specialDatesStylesOver[data.valueOf()];
	}
	data.setYear(-1);
	return this.specialDatesStylesOver[data.valueOf()];
};

oboutCalendar.prototype.getToolTip =
function(data) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
	data = new Date(data.getFullYear(), data.getMonth(), data.getDate(),0,0,0,0);
	if(typeof(this.specialDates[data.valueOf()]) != "undefined") {
		return this.specialDates[data.valueOf()];
	}
	data.setYear(-1);
	return this.specialDates[data.valueOf()];
};

oboutCalendar.prototype.compareDates =
function(date1, date2) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
	if(date1.getFullYear() < date2.getFullYear()) {
		return -1;
	}
	if(date1.getFullYear() > date2.getFullYear()) {
		return 1;
	}
	else {
		if(date1.getMonth() < date2.getMonth()) {
			return -1;
		}
		if(date1.getMonth() > date2.getMonth()) {
			return 1;
		}
		else {
			if(date1.getDate() < date2.getDate()) {
				return -1;
			}
			if(date1.getDate() > date2.getDate()) {
				return 1;
			}
			else {
				return 0;
			}
		}
	}
};
oboutCalendar.prototype.isSelected =
function(data, isSel) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
	if(this.selectedDate != null 
	    && this.compareDates(data, this.selectedDate) == 0 
	    // compare the time only on manual select
	    && (!this.timeSelector || !isSel || this.compareTimes(data, this.selectedDate, isSel) == 0)) {
		return true;
	}
	
	if (this.multiSelectedDates)
	{
	    // check the if the selected date exists into the selected dates array
	    if (this.selectedDates.length > 0)
	    {
	        for(selDatesIndex=0;selDatesIndex<this.selectedDates.length;selDatesIndex++)
	        {
	            if (this.selectedDates[selDatesIndex] != null 
	                && this.compareDates(data, this.selectedDates[selDatesIndex]) == 0)
	                return true;
	        }
	    }
	}
	
	return false;
};

oboutCalendar.prototype.compareTimes =
function(date1, date2, isSel) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    var date1Hours = date1.getHours(); 
    
    if(date1Hours < date2.getHours()) {
		return -1;
	}
	if(date1Hours > date2.getHours()) {
		return 1;
	}
	else {
		if(date1.getMinutes() < date2.getMinutes()) {
			return -1;
		}
		if(date1.getMinutes() > date2.getMinutes()) {
			return 1;
		}
		else {
			if(date1.getSeconds() < date2.getSeconds()) {
				return -1;
			}
			if(date1.getSeconds() > date2.getSeconds()) {
				return 1;
			}
			else {
				return 0;
			}
		}
	}
}

oboutCalendar.prototype.getLeft =
function(obj) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
	var pos = 0;
    var isAbsolute = false;

    if (!obj) return 0;
	if (this.isIE || this.isOpera)
	{
		var borderLeft = this.getStyle(obj, "border-left-width").replace("px", "");
		if (!isNaN(parseInt(borderLeft))) 
			pos += parseInt(borderLeft);
	}
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			if (typeof obj.style != 'undefined' && typeof obj.style.position != 'undefined' && obj.style.position.toLowerCase() == "absolute")
				isAbsolute = true;

			pos += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x) pos += obj.x;

	if (this.isSafari && !isAbsolute)
		pos += document.body.offsetLeft;

    return pos;
};

oboutCalendar.prototype.getTop =
function(obj) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
	var pos = 0;
    var count=0;
 
    if(this.isFirefox == true ||this.isOpera==true) {
        var arrUsedElements = new Array();
        var oInitialObj = obj;
    }
  
    if (obj)
    {      
       
        while (obj)
        {  
            count++;                  
            if(obj.nodeName != "TR" || this.isSafari == false) {
               pos += obj.offsetTop - ((obj.nodeName != "TR" && this.isOpera==false) ? obj.scrollTop : 0);
            } else {
                pos += obj.firstChild.offsetTop - obj.firstChild.scrollTop;
            }
            
            if(this.isIE)
            {
                if(!isNaN(parseInt(obj.currentStyle.borderTopWidth)))
                {
                    pos += parseInt(obj.currentStyle.borderTopWidth);
                }
              
            }
                      
            if(this.isFirefox == true||this.isOpera==true ) {
                arrUsedElements.push(obj);
            }
            if (this.isSafari && obj.parentNode.nodeName == "DIV") /* bug in safari - it omits div elements using offsetParent */
                obj = obj.parentNode;
            else    
                obj = obj.offsetParent;          
        }
    }
    else if (obj.y)
    {
        pos += obj.y;
    }
      
    if((this.isFirefox == true ||this.isOpera==true) && arrUsedElements.length > 0) {
        obj = oInitialObj;
        while(obj.parentNode) {          
            if(obj.nodeName == "DIV" && obj.style.position != "absolute" && obj.style.position != "relative" && obj.style.position != "fixed") {
                var bAlreadyUsed = false;
                for(var j=0; j<arrUsedElements.length; j++) {
                    if(arrUsedElements[j] == obj) {
                        bAlreadyUsed = true;
                        break;
                    }
                }
              
                if(bAlreadyUsed == false) {
                    pos -= obj.scrollTop;
                }
            }
      
            obj = obj.parentNode;
        }
    }
    return pos;
};

oboutCalendar.prototype.getStyle = 
function(oElm, strCssRule) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    var strValue = "";
    if(document.defaultView && document.defaultView.getComputedStyle)
        strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
    else if(oElm.currentStyle)
    {
		try
		{
			strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){return p1.toUpperCase();});
			strValue = oElm.currentStyle[strCssRule];
        }
        catch(ex){}
    }
    return strValue;
}

// extract date variable from a string using the specified format
oboutCalendar.prototype.extractDate =
function(data, format) {
    var result = [];
	// time format is also available
	var regexp = /yyyy|yy|y|MMMM|MMM|MM|M|dddd|ddd|dd|d|hh|h|mm|m|ss|s/g;
	
	var currentDate = new Date();
	
	var year = currentDate.getFullYear();
    var month = currentDate.getMonth();
    var day = currentDate.getDate();
    var hour = currentDate.getHours();
    var minute = currentDate.getMinutes();
    var second = currentDate.getSeconds();
	
	//split string at "'"
	var tmpStr = format.split("'");
	for(var i = 0; i < tmpStr.length; i++) {
		//save stuff within quotes
		if((i+1) % 2 == 0) {
			result.push(tmpStr[i]);
			continue;
		}
		var searchStartIndex = regexp.lastIndex;
		var ar;
		var indexIncrement = 0;
		while ((ar = regexp.exec(tmpStr[i])) != null) {
			var matchFoundIndex = ar.index;
			//save the nonmatched string
			result.push(tmpStr[i].slice(searchStartIndex, matchFoundIndex));
			searchStartIndex = regexp.lastIndex;
			var substrIndex = ar.index + indexIncrement;
			//convert match and save
			switch(ar[0]) {
				case 'yyyy':
				    year = parseInt(data.substr(substrIndex, ar[0].length)); break;
				case 'yy':
				    year = parseInt("20" + data.substr(substrIndex, ar[0].length)); break;
				case 'y':
				    year = parseInt("200" + data.substr(substrIndex, ar[0].length)); break;
				case 'MMMM':
				    for (index=0;index<this.longMonthNames.length;index++)
				    {
				        if (this.longMonthNames[index].indexOf(data.substr(substrIndex, ar[0].length)) == 0)
				        {
				            month = index;
				            // if long name is used then use on the first 4 letters
				            data = data.replace(this.longMonthNames[index], this.longMonthNames[index].substr(0, 4));
				            break;
				        }
				    }
				    break;
				case 'MMM':
				    for (index=0;index<this.shortMonthNames.length;index++)
				    {
				        if (data.substr(substrIndex, ar[0].length) == this.shortMonthNames[index])
				        {
				            month = index;
				            break;
				        }
				    }
					break;
				case 'MM':
					month = parseInt(data.substr(substrIndex, ar[0].length).replace(/^0/, '')) - 1; break;
			    case 'M':
				    // check for numbers bigger than 9
				    month = parseInt(data.substr(substrIndex, 2).replace(/^0/, ''));
				    if (isNaN(month) || month < 10)
				        month = parseInt(data.substr(substrIndex, 1).replace(/^0/, '')); 
				    else
				        indexIncrement++;
				    month = month - 1;
				    break;
				case 'dddd':
				case 'ddd':
					break;
				case 'dd':
				    day = parseInt(data.substr(substrIndex, ar[0].length).replace(/^0/, '')); break;
				case 'd':
				    // check for numbers bigger than 9
				    day = parseInt(data.substr(substrIndex, 2).replace(/^0/, ''));
				    if (isNaN(day) || day < 10)
				        day = parseInt(data.substr(substrIndex, 1).replace(/^0/, '')); 
				    else
				        indexIncrement++;
				    break;
				case 'hh':
				case 'h':
				    hour = parseInt(data.substr(substrIndex, ar[0].length).replace(/^0/, '')); break;
                case 'mm':
                case 'm':
				    minute = parseInt(data.substr(substrIndex, ar[0].length).replace(/^0/, '')); break;
                case 'ss':
                case 's':
                    second = parseInt(data.substr(substrIndex, ar[0].length).replace(/^0/, '')); break;
			}
		}
		//save nonmatched string
		result.push(tmpStr[i].slice(searchStartIndex));
	}
	
    var extractedDate = new Date();
    
    if (!isNaN(year)) extractedDate.setFullYear(year);
    if (!isNaN(month)) extractedDate.setMonth(month);
    if (!isNaN(day)) extractedDate.setDate(day);
    if (!isNaN(hour)) extractedDate.setHours(hour);
    if (!isNaN(minute)) extractedDate.setMinutes(minute);
    if (!isNaN(second)) extractedDate.setSeconds(second);
    
    return extractedDate;
}

oboutCalendar.prototype.formatDate =
function (data, format) {
    if (data == null) return data;
    var tmp = data.getFullYear() % 1000 % 100;
    var result = [];
    //var reg = /yyyy|yy|y|MMMM|MMM|MM|M|dddd|ddd|dd|d/g;
    // time format is also available

    var regexp = /yyyy|yy|y|MMMM|MMM|MM|M|dddd|ddd|dd|d|hh|h|mm|m|ss|s/g;
    
    //split string at "'"
    var tmpStr = format.split("'");
    for (var i = 0; i < tmpStr.length; i++) {
        //save stuff within quotes
        if ((i + 1) % 2 == 0) {
            result.push(tmpStr[i]);
            continue;
        }
        var searchStartIndex = regexp.lastIndex;
        var ar;
        regexp.exec('');
        regexp = /yyyy|yy|y|MMMM|MMM|MM|M|dddd|ddd|dd|d|hh|h|mm|m|ss|s/g;
        while ((ar = regexp.exec(tmpStr[i])) != null) {
            var matchFoundIndex = ar.index;
            //save the nonmatched string
            result.push(tmpStr[i].slice(searchStartIndex, matchFoundIndex));
            searchStartIndex = regexp.lastIndex;
            //convert match and save
            switch (ar[0]) {
                case 'yyyy':
                    result.push(data.getFullYear()); break;
                case 'yy':
                    result.push(((tmp < 10) ? "0" : "") + tmp); break;
                case 'y':
                    result.push(tmp); break;
                case 'MMMM':
                    result.push(this.longMonthNames[data.getMonth()]); break;
                case 'MMM':
                    result.push(this.shortMonthNames[data.getMonth()]); break;
                case 'MM':
                    result.push(((data.getMonth() < 9) ? "0" : "") + (data.getMonth() + 1)); break;
                case 'M':
                    result.push((data.getMonth() + 1).toString()); break;
                case 'dddd':
                    result.push(this.longDayNames[data.getDay()]); break;
                case 'ddd':
                    result.push(this.shortDayNames[data.getDay()]); break;
                case 'dd':
                    result.push(((data.getDate() < 10) ? "0" : "") + data.getDate()); break;
                case 'd':
                    result.push(data.getDate()); break;
                case 'hh':
                    result.push(((data.getHours() < 10) ? "0" : "") + data.getHours()); break;
                case 'h':
                    result.push(data.getHours()); break;
                case 'mm':
                    result.push(((data.getMinutes() < 10) ? "0" : "") + data.getMinutes()); break;
                case 'm':
                    result.push(data.getMinutes()); break;
                case 'ss':
                    result.push(((data.getSeconds() < 10) ? "0" : "") + data.getSeconds()); break;
                case 's':
                    result.push(data.getSeconds()); break;

            }
        }
        //save nonmatched string
        result.push(tmpStr[i].slice(searchStartIndex));
    }
    return result.join("");
};

oboutCalendar.prototype.setDate =
function(firstMonthDate, selectedDate) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    var hours = 9;
    var minutes = 0;
    var seconds = 0;
    var milliseconds = 999;
    
    if (this.timeSelector && selectedDate != null)
    {
        hours = selectedDate.getHours();
        minutes = selectedDate.getMinutes();
        seconds = selectedDate.getSeconds();
    }
    
	this.addToQueue(this.id + "." + (("switchView")) + ((firstMonthDate != null)?("(new Date(" + firstMonthDate.getFullYear() + "," + firstMonthDate.getMonth() + "," + firstMonthDate.getDate() + ",9,0,0,999)"):"(null") + "," + ((selectedDate != null)?(" new Date(" + selectedDate.getFullYear() + "," + selectedDate.getMonth() + "," + selectedDate.getDate() + "," + hours + "," + minutes + "," + seconds + "," + milliseconds + ")"):"null") + ", true);");
    
	// select the year/month/hour/minute/second from the year/month/hour/minute/second selector
	this.updateYearSelector((selectedDate != null) ? selectedDate.getFullYear() : ((firstMonthDate != null) ? firstMonthDate.getFullYear() : new Date().getFullYear()));
	this.updateMonthSelector((selectedDate != null) ? selectedDate.getMonth() : ((firstMonthDate != null) ? firstMonthDate.getMonth() : new Date().getMonth()));
	
    if(!this.didOnceOnSelect) {
		if(this.startDateCalendarId != null && this.startDateCalendar == null) { // try to find the calendar for starting date
			this.startDateCalendar = eval("if(typeof("+this.startDateCalendarId+")==\"undefined\") null; else "+this.startDateCalendarId+";");
			if(this.startDateCalendar != null) {
				this.startDateCalendar.endDateCalendar = this;
			}
		}
		else if(this.endDateCalendar == null) { // if this is a start date calendar, then look for end date variable
			this.endDateCalendar = eval("if(typeof("+this.id+"endDate)==\"undefined\") null; else "+this.id+"endDate;");
			if(this.endDateCalendar != null) {
				this.endDateCalendar.startDateCalendar = this;
			}
		}
		this.didOnceOnSelect = true;
	}
	
    // is begin start calendar exists then synchronize the date
    if(this.startDateCalendar != null) {
		//check if other calendar has a selected date and if it is greater 
		//than this calendar selected date.  If it is, then need to change it.
		if(this.startDateCalendar.selectedDate == null || (this.startDateCalendar.selectedDate != null && this.compareDates(this.startDateCalendar.selectedDate, this.selectedDate) > 0)) {
			this.startDateCalendar.updateYearSelector(this.selectedDate.getFullYear());
			this.startDateCalendar.updateMonthSelector(this.selectedDate.getMonth());
			this.startDateCalendar.addToQueue(this.startDateCalendar.id + "." + (("switchView")) + "(new Date(" + this.selectedDate.getFullYear() + "," + this.selectedDate.getMonth() + "," + this.selectedDate.getDate() + ",9,0,0,999), new Date(" + this.selectedDate.getFullYear() + "," + this.selectedDate.getMonth() + "," + this.selectedDate.getDate() + ",9,0,0,999), false);");
		}
	}
	else if(this.endDateCalendar != null) {
		if(this.endDateCalendar.selectedDate == null || (this.endDateCalendar.selectedDate != null && this.compareDates(this.endDateCalendar.selectedDate, this.selectedDate) < 0)) {
			this.endDateCalendar.updateYearSelector(this.selectedDate.getFullYear());
			this.endDateCalendar.updateMonthSelector(this.selectedDate.getMonth());
			this.endDateCalendar.addToQueue(this.endDateCalendar.id + "." + (("switchView")) + "(new Date(" + this.selectedDate.getFullYear() + "," + this.selectedDate.getMonth() + "," + this.selectedDate.getDate() + ",9,0,0,999), new Date(" + this.selectedDate.getFullYear() + "," + this.selectedDate.getMonth() + "," + this.selectedDate.getDate() + ",9,0,0,999), true);");
		}
	}
};

// add document.onclick event
oboutCalendar.prototype.addClickEvent = 
function (func) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    var oldonclick = document.onclick;
    if (typeof document.onclick != 'function') 
    {
        document.onclick = func;
    } 
    else 
    {
        document.onclick = function() 
        {
            if (oldonclick) 
            {
                oldonclick();
            }
            func();
        }
    }
}

oboutCalendar.prototype.knackerevent = 
function(eventObject) { 
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    if (eventObject && eventObject.stopPropagation != undefined) 
    { 
        eventObject.stopPropagation(); 
    } 
    if (window.event && window.event.cancelBubble != undefined) 
    { 
        window.event.cancelBubble = true; 
    } 
    if (eventObject && eventObject.preventDefault != undefined) 
    { 
        eventObject.preventDefault(); 
    } 
    if (window.event) 
    { 
        window.event.returnValue = false; 
    } 
}

oboutCalendar.prototype.onClientDateChanged = null;
oboutCalendar.prototype.onClientDateMouseOver = null;
oboutCalendar.prototype.onClientDateMouseOut = null;

// a month selection was made on the month selector
oboutCalendar.prototype.selectMonth =
function (month) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();

    // month selector as dropdownlist is available
    var ddlMonthSelector = document.getElementById("_" + this.id + "Month");
    if (ddlMonthSelector != null) {
        // update the dropdownlist - is done automatically
    }

    // month selector as htmllist is available
    var MonthSelectorTitle = document.getElementById(this.id + "_MonthSelectorTitle");
    if (MonthSelectorTitle != null) {
        // update the html list view
        this.updateMonthHTMLList(month);
    }

    // update the calendar
    // calculate the correct month to jump at
    var firstMonthToJumpAt = month - (this.lastMonth + (this.lastYear - this.firstYear)*12);
    //alert(firstMonthToJumpAt + "---" + month + "---" + this.lastMonth);
    //alert(this.firstYear +"---"+ this.lastYear);

    // the year has changed then we need to decrease months by 12
    /*if (!isNaN(this.firstYear) && this.firstYear < this.lastYear) {
    firstMonthToJumpAt -= 12;
    }*/

    //this.firstYear = this.lastYear;

    this.incrementMonth(firstMonthToJumpAt);
    this.switchView(null, null, true);
}

// updates the month selector - in case of month scrolling, setDate client method call
oboutCalendar.prototype.updateMonthSelector =
function(month) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    // month selector as drop down list is available
    var ddlMonthSelector = document.getElementById("_" + this.id + "Month");
    if (ddlMonthSelector != null)
    {
        ddlMonthSelector.value = month;
    }
    
    // month selector as html list is available
    var MonthSelectorTitle = document.getElementById(this.id + "_MonthSelectorTitle");
    if (MonthSelectorTitle != null)
    {   
        this.updateMonthHTMLList(month);
    }
}

oboutCalendar.prototype.updateMonthHTMLList = 
function(month) {
    // hide the month selector
    this.displayMonthSelector('none');
    
    // change the selected month from the month selector title container
    var MonthSelectorTitle = document.getElementById(this.id + "_MonthSelectorTitle");
    MonthSelectorTitle.innerHTML = this.longMonthNames[month];
    
    var controlId = this.id;
    var localStyleMonthSelected = this.styleMonthSelected;
    var localStyleMonth = this.styleMonthSelector;
    
    for (var monthIndex = 0; monthIndex < 12; monthIndex++)
    {
        var lastMonthElement = document.getElementById(this.id + "_Month" + monthIndex);
        this.changeStyle(lastMonthElement, this.styleMonthSelector);
        // attach mouseover/mouseout effects for the old selected month
        if (lastMonthElement != null)
        {
            lastMonthElement.onmouseover = function() {eval(controlId + ".setMonthSelectorOverEffect(this, '" + localStyleMonthSelected + "')");};
            lastMonthElement.onmouseout = function() {eval(controlId + ".setMonthSelectorOverEffect(this, '" + localStyleMonth + "')");};
        }
    }
    
    // set the css class for the current select month
    var selectedMonthElement = document.getElementById(this.id + "_Month" + month);
    this.changeStyle(selectedMonthElement, this.styleMonthSelected);
    // dettach mouseover/mouseout effects for the old selected month
    if (selectedMonthElement != null)
    {
        selectedMonthElement.onmouseover = function() {};
        selectedMonthElement.onmouseout = function() {};
    }
}

oboutCalendar.prototype.setMonthSelectorOverEffect =
function(element, cssClass) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    if (document.getElementById(this.id + "_MonthSelectorContainer").style.display != 'none')
        this.changeStyle(element, cssClass);
}

oboutCalendar.prototype.displayMonthSelector =
function(display, docEvent) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    if (display != "none")
    {
        // hide year,hour,minute,second selectors
        if (document.getElementById(this.id + "_YearSelectorContainer")) this.displayYearSelector('none');
        
        if (document.getElementById(this.id + "_HourSelectorContainer")) this.displayHourSelector('none');
        if (document.getElementById(this.id + "_MinuteSelectorContainer")) this.displayMinuteSelector('none');
        if (document.getElementById(this.id + "_SecondSelectorContainer")) this.displaySecondSelector('none');
    }

    var MonthSelectorContainer = document.getElementById(this.id + "_MonthSelectorContainer");
    var MonthSelectorTitle = document.getElementById(this.id + "_MonthSelectorTitle");
    var MonthSelectorIframe = document.getElementById("_" + this.id + "_MonthSelectorIframe");
    
    if (display == "none")
    {
        // hide the month selector container
        MonthSelectorContainer.style.display = "none";
        MonthSelectorIframe.style.display = "none";
    }
    else
    {
        // attach the container directly to the document object
        if (document.body != MonthSelectorContainer.parentNode)
            document.body.insertBefore(MonthSelectorContainer, document.body.firstChild);
            
        // attach the container iframe directly to the document object
        if (document.body != MonthSelectorIframe.parentNode)
            document.body.insertBefore(MonthSelectorIframe, document.body.firstChild);
            
        MonthSelectorContainer.style.display = "inline";
        MonthSelectorContainer.style.zIndex = "10003";
        MonthSelectorContainer.style.position = "absolute";
        
        // get the month selector title position
        var left = this.findPosX(MonthSelectorTitle);
        var top = this.findPosY(MonthSelectorTitle) + MonthSelectorTitle.offsetHeight;
        
        MonthSelectorContainer.style.left = left + "px";
        MonthSelectorContainer.style.top = top + "px";
        
        if(this.isIE) { //show the iframe in IE only
		    MonthSelectorIframe.style.zIndex = "10002";
		    MonthSelectorIframe.style.height = MonthSelectorContainer.offsetHeight + "px";
		    MonthSelectorIframe.style.width = MonthSelectorContainer.offsetWidth + "px";
		    MonthSelectorIframe.style.display = "inline";
		    MonthSelectorIframe.style.position = "absolute";
	        MonthSelectorIframe.style.top = top + "px";
		    MonthSelectorIframe.style.left = left + "px";
	    } 
    }
    
    this.isWorking = false; 
}

// a year selection was made on the year selector
oboutCalendar.prototype.selectYear =
function (year) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();

    // year selector as dropdownlist is available
    var ddlYearSelector = document.getElementById("_" + this.id + "Year");
    if (ddlYearSelector != null) {
        // update the dropdownlist - is done automatically
    }

    // year selector as htmllist is available
    var YearSelectorTitle = document.getElementById(this.id + "_YearSelectorTitle");
    if (YearSelectorTitle != null) {
        // update the html list view
        this.updateYearHTMLList(year);
    }

    // update the calendar
    // calculate the correct year to jump at
    
    //var firstYearToJumpAt = year - this.lastYear;

//    var monthToJumpAt = 12 * firstYearToJumpAt - this.rows * this.cols + 1;

//    if (this.cols - this.lastMonth == 2) {
//        monthToJumpAt += 12;
//    }

    this.lastMonth = this.firstMonth;
    this.lastYear = year;
    //this.incrementMonth(monthToJumpAt);
    this.switchView(null, null, true);
}

// updates the year selector - in case of month scrolling, setDate client method call
oboutCalendar.prototype.updateYearSelector =
function(year) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    // month selector as drop down list is available
    var ddlYearSelector = document.getElementById("_" + this.id + "Year");
    if (ddlYearSelector != null)
    {
        ddlYearSelector.value = year;
    }
    
    // year selector as html list is available
    var YearSelectorTitle = document.getElementById(this.id + "_YearSelectorTitle");
    if (YearSelectorTitle != null)
    {   
        this.updateYearHTMLList(year);
    }
}

oboutCalendar.prototype.updateYearHTMLList = 
function(year) {
    // hide the year selector
    this.displayYearSelector('none');
    
    // change the selected year from the year selector title container
    var YearSelectorTitle = document.getElementById(this.id + "_YearSelectorTitle");
    YearSelectorTitle.innerHTML = year;
    var minYear = YearSelectorTitle.getAttribute("minYear");
    var maxYear = YearSelectorTitle.getAttribute("maxYear");
    
    var controlId = this.id;
    var localStyleYearSelected = this.styleYearSelected;
    var localStyleYear = this.styleYearSelector;
    
    for (var yearIndex = minYear; yearIndex <= maxYear; yearIndex++)
    {
        var lastYearElement = document.getElementById(this.id + "_Year" + yearIndex);
        this.changeStyle(lastYearElement, this.styleYearSelector);
        // attach mouseover/mouseout effects for the old selected year
        if (lastYearElement != null)
        {
            lastYearElement.onmouseover = function() {eval(controlId + ".setYearSelectorOverEffect(this, '" + localStyleYearSelected + "')");};
            lastYearElement.onmouseout = function() {eval(controlId + ".setYearSelectorOverEffect(this, '" + localStyleYear + "')");};
        }
    }
    
    // set the css class for the current select year
    var selectedYearElement = document.getElementById(this.id + "_Year" + year);
    this.changeStyle(selectedYearElement, this.styleYearSelected);
    // dettach mouseover/mouseout effects for the old selected year
    if (selectedYearElement != null)
    {
        selectedYearElement.onmouseover = function() {};
        selectedYearElement.onmouseout = function() {};
    }
}

oboutCalendar.prototype.setYearSelectorOverEffect =
function(element, cssClass) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    if (document.getElementById(this.id + "_YearSelectorContainer").style.display != 'none')
        this.changeStyle(element, cssClass);
}

oboutCalendar.prototype.yearSelectorScrollerTimer;
oboutCalendar.prototype.yearSelectorAutomatMoverTriggered;

oboutCalendar.prototype.yearSelectorMoveDownScroll =
function(eventType) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    if (eventType=="start")
    {
        this.yearSelectorScrollerTimer = setTimeout(this.id + ".yearSelectorMoveDown(true)", this.firstYearSelectorScrollSpeed);
        this.yearSelectorAutomatMoverTriggered = true;
    }
    if (eventType=="end")
    {
        clearTimeout(this.yearSelectorScrollerTimer);
    }
}

oboutCalendar.prototype.yearSelectorMoveUpScroll =
function(eventType) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    if (eventType=="start")
    {
        this.yearSelectorScrollerTimer = setTimeout(this.id + ".yearSelectorMoveUp(true)", this.firstYearSelectorScrollSpeed);
        this.yearSelectorAutomatMoverTriggered = true;
    }
    if (eventType=="end")
    {
        clearTimeout(this.yearSelectorScrollerTimer);
    }
}

oboutCalendar.prototype.yearSelectorMoveDown =
function(timer) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    if (timer) 
        this.yearSelectorScrollerTimer = setTimeout(this.id + ".yearSelectorMoveDown(true)", this.yearSelectorScrollSpeed);
    else
    { 
        if (this.yearSelectorAutomatMoverTriggered)
        {
            this.yearSelectorAutomatMoverTriggered = false;
            this.isWorking = false;
            return;
        }
    }
    var YearSelectorContainer = document.getElementById(this.id + "_YearSelectorContainer");
    var containers = YearSelectorContainer.childNodes[0].childNodes;
    var firstYear = true;
    var lastYear = true;
    var yearsDisplayed = 0;
    for (var index = 0; index < containers.length; index++)
    {
        var year = containers[index].getAttribute("year");
        if (year != null && document.getElementById(this.id + "_Year" + year).style.display != 'none') yearsDisplayed++;
    }
    
    var yearHidden = false;
    for (var index = 0; index < containers.length; index++)
    {
        var year = containers[index].getAttribute("year");
        if (year != null) year = parseInt(year);
        
        if (year != null)
        {
            // this is the first year - move up
            if (document.getElementById(this.id + "_Year" + year) && 
                document.getElementById(this.id + "_Year" + year).style.display != 'none' &&
                document.getElementById(this.id + "_Year" + (year + yearsDisplayed)))
            {
                document.getElementById(this.id + "_Year" + year).style.display = "none";
                yearHidden = true;
            }
            
            // this is the first year - move up
            if (yearHidden && document.getElementById(this.id + "_Year" + (year + yearsDisplayed)))
            {
                document.getElementById(this.id + "_Year" + (year + yearsDisplayed)).style.display = "";
                
                break;
            }
        }
    }
    
    this.isWorking = false;
}

oboutCalendar.prototype.yearSelectorMoveUp =
function(timer) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    if (timer) this.yearSelectorScrollerTimer = setTimeout(this.id + ".yearSelectorMoveUp(true)", this.yearSelectorScrollSpeed);
    else
    { 
        if (this.yearSelectorAutomatMoverTriggered)
        {
            this.yearSelectorAutomatMoverTriggered = false;
            this.isWorking = false;
            return;
        }
    }
    
    var YearSelectorContainer = document.getElementById(this.id + "_YearSelectorContainer");
    var containers = YearSelectorContainer.childNodes[0].childNodes;
    var firstYear = true;
    var lastYear = true;
    var yearsDisplayed = 0;
    for (var index = 0; index < containers.length; index++)
    {
        var year = containers[index].getAttribute("year");
        if (year != null && document.getElementById(this.id + "_Year" + year).style.display != 'none') yearsDisplayed++;
    }
    
    var yearHidden = false;
    for (var index = 0; index < containers.length; index++)
    {
        var year = containers[index].getAttribute("year");
        if (year != null) year = parseInt(year);
        
        if (year != null)
        {
            // this is the first year - move up
            if (document.getElementById(this.id + "_Year" + year) && 
                document.getElementById(this.id + "_Year" + year).style.display != 'none' &&
                document.getElementById(this.id + "_Year" + (year - 1)) &&
                document.getElementById(this.id + "_Year" + (year + yearsDisplayed - 1)))
            {
                document.getElementById(this.id + "_Year" + (year - 1)).style.display = "";
                yearHidden = true;
            }
            
            // this is the first year - move up
            if (yearHidden && document.getElementById(this.id + "_Year" + (year + yearsDisplayed - 1)))
            {
                document.getElementById(this.id + "_Year" + (year + yearsDisplayed - 1)).style.display = "none";
                
                break;
            }
        }
    }
    
    this.isWorking = false;
}

oboutCalendar.prototype.displayYearSelector =
function(display, docEvent) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    if (display != "none")
    {
        // hide year,hour,minute,second selectors
        
        if (document.getElementById(this.id + "_MonthSelectorContainer")) this.displayMonthSelector('none');
        if (document.getElementById(this.id + "_HourSelectorContainer")) this.displayHourSelector('none');
        if (document.getElementById(this.id + "_MinuteSelectorContainer")) this.displayMinuteSelector('none');
        if (document.getElementById(this.id + "_SecondSelectorContainer")) this.displaySecondSelector('none');
    }

    var YearSelectorContainer = document.getElementById(this.id + "_YearSelectorContainer");
    var YearSelectorTitle = document.getElementById(this.id + "_YearSelectorTitle");
    var YearSelectorIframe = document.getElementById("_" + this.id + "_YearSelectorIframe");
    
    if (display == "none")
    {
        // hide the year selector container
        YearSelectorContainer.style.display = "none";
        YearSelectorIframe.style.display = "none";
    }
    else
    {
        // attach the container directly to the document object
        if (document.body != YearSelectorContainer.parentNode)
            document.body.insertBefore(YearSelectorContainer, document.body.firstChild);
            
        // attach the container iframe directly to the document object
        if (document.body != YearSelectorIframe.parentNode)
            document.body.insertBefore(YearSelectorIframe, document.body.firstChild);
            
        YearSelectorContainer.style.display = "inline";
        YearSelectorContainer.style.zIndex = "10003";
        YearSelectorContainer.style.position = "absolute";
        
        // get the year selector title position
        var left = this.findPosX(YearSelectorTitle);
        var top = this.findPosY(YearSelectorTitle) + YearSelectorTitle.offsetHeight;
        
        YearSelectorContainer.style.left = left + "px";
        YearSelectorContainer.style.top = top + "px";
        
        if(this.isIE) { //show the iframe in IE only
		    YearSelectorIframe.style.zIndex = "10002";
		    YearSelectorIframe.style.height = YearSelectorContainer.offsetHeight + "px";
		    YearSelectorIframe.style.width = YearSelectorContainer.offsetWidth + "px";
		    YearSelectorIframe.style.display = "inline";
		    YearSelectorIframe.style.position = "absolute";
	        YearSelectorIframe.style.top = top + "px";
		    YearSelectorIframe.style.left = left + "px";
	    } 
    }
    
    this.isWorking = false; 
}

//Get time from time selectors
oboutCalendar.prototype.getTime =
function() {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    if (this.timeSelector)
    {
        var hour = 0;
        var minute = 0;
        var second = 0;
        
        if (document.getElementById("_" + this.id + "Hour") != null)
        {
            hour = document.getElementById("_" + this.id + "Hour");
            hour = hour.options[hour.selectedIndex].value;
        }
        
        if (document.getElementById("_" + this.id + "Minute") != null)
        {
            minute = document.getElementById("_" + this.id + "Minute");
            minute = minute.options[minute.selectedIndex].value;
        }
        
        if (document.getElementById("_" + this.id + "Second") != null)
        {
            second = document.getElementById("_" + this.id + "Second");
            second = second.options[second.selectedIndex].value;
        }
        
        // hour selector as htmllist is available
        if (document.getElementById(this.id + "_HourSelectorTitle") != null)
            hour = parseInt(document.getElementById(this.id + "_HourSelectorTitle").innerHTML, 10);
        
        // minute selector as htmllist is available
        if (document.getElementById(this.id + "_MinuteSelectorTitle") != null)
            minute = parseInt(document.getElementById(this.id + "_MinuteSelectorTitle").innerHTML, 10);
            
        // second selector as htmllist is available
        if (document.getElementById(this.id + "_SecondSelectorTitle") != null)
            second = parseInt(document.getElementById(this.id + "_SecondSelectorTitle").innerHTML, 10);
    
        return eval('(' + '{"Hour":' + hour + ', "Minute":' + minute + ', "Second":' + second + '}' + ')');
    }
    
    return null;
}

//Updates the Time selector once the 'Set' is called
//Updates the hour, minute, second selectors' title and style of selected option
oboutCalendar.prototype.setTime =
function(hour, minute, second) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    if (this.timeSelector)
    {
        this.updateHourSelector(hour);
        this.updateMinuteSelector(minute);
        this.updateSecondSelector(second);
    }
}

oboutCalendar.prototype.updSD =
function(date, timeChange, isBuild) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    if (date == null && this.selectedDate != null)
            date = new Date(this.selectedDate.getYear(), this.selectedDate.getMonth(), this.selectedDate.getDate(), 
                this.selectedDate.getHours(), this.selectedDate.getMinutes(), this.selectedDate.getSeconds());
        
    if (date == null)
        return;
        
    var time = this.getTime();
	if (time != null && !isBuild)
	{
	    date.setHours(time["Hour"]);
	    date.setMinutes(time["Minute"]);
	    date.setSeconds(time["Second"]);
	}
}

// a hour selection was made on the hour selector
oboutCalendar.prototype.selectHour = 
function(hour) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    // hour selector as dropdownlist is available
    var ddlHourSelector = document.getElementById("_" + this.id + "Hour");
    if (ddlHourSelector != null)
    {
        // update the dropdownlist - is done automatically
    }
    
    // hour selector as htmllist is available
    var HourSelectorTitle = document.getElementById(this.id + "_HourSelectorTitle");
    if (HourSelectorTitle != null)
    {   
        // update the html list view
        this.updateHourHTMLList(hour);
    }
    
    if (this.selectedDate != null)
        this.selectedDate.setHours(hour);
        
    //populate hidden field
    if(!this.datePickerMode && this.hiddenField != null && this.selectedDate != null) {
        //populate hidden field
		if(this.hiddenField != null) {
		    // add also the selected time
	        var time = this.getTime();
	        var timeString = "";
	        if (time != null)    
	            timeString = ";" + time["Hour"] + "." + time["Minute"] + "." + time["Second"];
			this.incrementMonth(-this.rows*this.cols+1);
			this.hiddenField.value = this.selectedDate.getFullYear()+"."+(this.selectedDate.getMonth()+1)+"."+this.selectedDate.getDate()+";"+this.lastYear+"."+(this.lastMonth+1)+".1" + timeString;
			this.incrementMonth(this.rows*this.cols-1);
		}
    }
        
    this.isWorking = false;
}

// updates the hour selector - in case of hour scrolling, setDate client method call
oboutCalendar.prototype.updateHourSelector =
function(hour) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    // hour selector as drop down list is available
    var ddlHourSelector = document.getElementById("_" + this.id + "Hour");
    if (ddlHourSelector != null)
    {
        ddlHourSelector.value = hour;
    }
    
    // hour selector as html list is available
    var HourSelectorTitle = document.getElementById(this.id + "_HourSelectorTitle");
    if (HourSelectorTitle != null)
    {   
        this.updateHourHTMLList(hour);
    }
}

oboutCalendar.prototype.updateHourHTMLList = 
function(hour) {
    // hide the hour selector
    this.displayHourSelector('none');
    
    // change the selected hour from the hour selector title container
    var HourSelectorTitle = document.getElementById(this.id + "_HourSelectorTitle");
    HourSelectorTitle.innerHTML = hour < 10 ? "0" + hour : hour;
    
    var controlId = this.id;
    var localStyleHourSelected = this.styleHourSelected;
    var localStyleHour = this.styleHourSelector;
    
    for (var hourIndex = 0; hourIndex < 23; hourIndex++)
    {
        var lastHourElement = document.getElementById(this.id + "_Hour" + hourIndex);
        this.changeStyle(lastHourElement, this.styleHourSelector);
        // attach mouseover/mouseout effects for the old selected hour
        if (lastHourElement != null)
        {
            lastHourElement.onmouseover = function() {eval(controlId + ".setHourSelectorOverEffect(this, '" + localStyleHourSelected + "')");};
            lastHourElement.onmouseout = function() {eval(controlId + ".setHourSelectorOverEffect(this, '" + localStyleHour + "')");};
        }
    }
    
    // set the css class for the current select hour
    var selectedHourElement = document.getElementById(this.id + "_Hour" + hour);
    this.changeStyle(selectedHourElement, this.styleHourSelected);
    // dettach mouseover/mouseout effects for the old selected hour
    if (selectedHourElement != null)
    {
        selectedHourElement.onmouseover = function() {};
        selectedHourElement.onmouseout = function() {};
    }
}

// a minute selection was made on the minute selector
oboutCalendar.prototype.selectMinute = 
function(minute) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    // minute selector as dropdownlist is available
    var ddlMinuteSelector = document.getElementById("_" + this.id + "Minute");
    if (ddlMinuteSelector != null)
    {
        // update the dropdownlist - is done automatically
    }
    
    // minute selector as htmllist is available
    var MinuteSelectorTitle = document.getElementById(this.id + "_MinuteSelectorTitle");
    if (MinuteSelectorTitle != null)
    {   
        // update the html list view
        this.updateMinuteHTMLList(minute);
    }
    
    if (this.selectedDate != null)
        this.selectedDate.setMinutes(minute);
        
    //populate hidden field
    if(!this.datePickerMode && this.hiddenField != null && this.selectedDate != null) {
        //populate hidden field
		if(this.hiddenField != null) {
		    // add also the selected time
	        var time = this.getTime();
	        var timeString = "";
	        if (time != null)    
	            timeString = ";" + time["Hour"] + "." + time["Minute"] + "." + time["Second"];
			this.incrementMonth(-this.rows*this.cols+1);
			this.hiddenField.value = this.selectedDate.getFullYear()+"."+(this.selectedDate.getMonth()+1)+"."+this.selectedDate.getDate()+";"+this.lastYear+"."+(this.lastMonth+1)+".1" + timeString;
			this.incrementMonth(this.rows*this.cols-1);
		}
    }
        
    this.isWorking = false;
}

// updates the minute selector - in case of minute scrolling, setDate client method call
oboutCalendar.prototype.updateMinuteSelector =
function(minute) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    // minute selector as drop down list is available
    var ddlMinuteSelector = document.getElementById("_" + this.id + "Minute");
    if (ddlMinuteSelector != null)
    {
        ddlMinuteSelector.value = minute;
    }
    
    // minute selector as html list is available
    var MinuteSelectorTitle = document.getElementById(this.id + "_MinuteSelectorTitle");
    if (MinuteSelectorTitle != null)
    {   
        this.updateMinuteHTMLList(minute);
    }
}

oboutCalendar.prototype.updateMinuteHTMLList = 
function(minute) {
    // hide the minute selector
    this.displayMinuteSelector('none');
    
    // change the selected minute from the minute selector title container
    var MinuteSelectorTitle = document.getElementById(this.id + "_MinuteSelectorTitle");
    MinuteSelectorTitle.innerHTML = minute < 10 ? "0" + minute : minute;
    
    var controlId = this.id;
    var localStyleMinuteSelected = this.styleMinuteSelected;
    var localStyleMinute = this.styleMinuteSelector;
    
    for (var minuteIndex = 0; minuteIndex < 23; minuteIndex++)
    {
        var lastMinuteElement = document.getElementById(this.id + "_Minute" + minuteIndex);
        this.changeStyle(lastMinuteElement, this.styleMinuteSelector);
        // attach mouseover/mouseout effects for the old selected minute
        if (lastMinuteElement != null)
        {
            lastMinuteElement.onmouseover = function() {eval(controlId + ".setMinuteSelectorOverEffect(this, '" + localStyleMinuteSelected + "')");};
            lastMinuteElement.onmouseout = function() {eval(controlId + ".setMinuteSelectorOverEffect(this, '" + localStyleMinute + "')");};
        }
    }
    
    // set the css class for the current select minute
    var selectedMinuteElement = document.getElementById(this.id + "_Minute" + minute);
    this.changeStyle(selectedMinuteElement, this.styleMinuteSelected);
    // dettach mouseover/mouseout effects for the old selected minute
    if (selectedMinuteElement != null)
    {
        selectedMinuteElement.onmouseover = function() {};
        selectedMinuteElement.onmouseout = function() {};
    }
}

// a second selection was made on the second selector
oboutCalendar.prototype.selectSecond = 
function(second) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    // second selector as dropdownlist is available
    var ddlSecondSelector = document.getElementById("_" + this.id + "Second");
    if (ddlSecondSelector != null)
    {
        // update the dropdownlist - is done automatically
    }
    
    // second selector as htmllist is available
    var SecondSelectorTitle = document.getElementById(this.id + "_SecondSelectorTitle");
    if (SecondSelectorTitle != null)
    {   
        // update the html list view
        this.updateSecondHTMLList(second);
    }
    
    if (this.selectedDate != null)
        this.selectedDate.setSeconds(second);
        
    //populate hidden field
    if(!this.datePickerMode && this.hiddenField != null && this.selectedDate != null) {
        //populate hidden field
		if(this.hiddenField != null) {
		    // add also the selected time
	        var time = this.getTime();
	        var timeString = "";
	        if (time != null)    
	            timeString = ";" + time["Hour"] + "." + time["Minute"] + "." + time["Second"];
			this.incrementMonth(-this.rows*this.cols+1);
			this.hiddenField.value = this.selectedDate.getFullYear()+"."+(this.selectedDate.getMonth()+1)+"."+this.selectedDate.getDate()+";"+this.lastYear+"."+(this.lastMonth+1)+".1" + timeString;
			this.incrementMonth(this.rows*this.cols-1);
		}
    }
        
    this.isWorking = false;
}

// updates the second selector - in case of second scrolling, setDate client method call
oboutCalendar.prototype.updateSecondSelector =
function(second) {
    // check if calendar is initialized
    if (!this.init && !this.initStarted) this.initCalendar();
    
    // second selector as drop down list is available
    var ddlSecondSelector = document.getElementById("_" + this.id + "Second");
    if (ddlSecondSelector != null)
    {
        ddlSecondSelector.value = second;
    }
    
    // second selector as html list is available
    var SecondSelectorTitle = document.getElementById(this.id + "_SecondSelectorTitle");
    if (SecondSelectorTitle != null)
    {   
        this.updateSecondHTMLList(second);
    }
}


//Creates Second selector Htmllist, each item in the list has IDs like CalID_Second1,CalID_Second2,CalID_Second3,CalID_Second4............
oboutCalendar.prototype.updateSecondHTMLList = 
function(second) {
    // hide the second selector
    this.displaySecondSelector('none');
    
    // change the selected second from the second selector title container
    var SecondSelectorTitle = document.getElementById(this.id + "_SecondSelectorTitle");
    SecondSelectorTitle.innerHTML = second < 10 ? "0" + second : second;
    
    var controlId = this.id;
    var localStyleSecondSelected = this.styleSecondSelected;
    var localStyleSecond = this.styleSecondSelector;
    
    for (var secondIndex = 0; secondIndex < 23; secondIndex++)
    {
        var lastSecondElement = document.getElementById(this.id + "_Second" + secondIndex);
        this.changeStyle(lastSecondElement, this.styleSecondSelector);
        // attach mouseover/mouseout effects for the old selected second
        if (lastSecondElement != null)
        {
            lastSecondElement.onmouseover = function() {eval(controlId + ".setSecondSelectorOverEffect(this, '" + localStyleSecondSelected + "')");};
            lastSecondElement.onmouseout = function() {eval(controlId + ".setSecondSelectorOverEffect(this, '" + localStyleSecond + "')");};
        }
    }
    
    // set the css class for the current select second
    var selectedSecondElement = document.getElementById(this.id + "_Second" + second);
    this.changeStyle(selectedSecondElement, this.styleSecondSelected);
    // dettach mouseover/mouseout effects for the old selected second
    if (selectedSecondElement != null)
    {
        selectedSecondElement.onmouseover = function() {};
        selectedSecondElement.onmouseout = function() {};
    }
}

oboutCalendar.prototype.selectTime = 
function() {
    if (this.selectedDate != null)
    {
        // set the date/time to textbox
        this.textbox.value = this.formatDate(this.selectedDate, this.dateFormat);
        
        var selDate = this.selectedDate;
        if(this.hiddenField != null && selDate != null) {
	        // add also the selected time
	        var time = this.getTime();
	        var timeString = "";
	        if (time != null)    
	            timeString = ";" + time["Hour"] + "." + time["Minute"] + "." + time["Second"];
	        this.incrementMonth(-this.rows*this.cols+1);
		    this.hiddenField.value = selDate.getFullYear()+"."+(selDate.getMonth() + 1)+"."+selDate.getDate()+";"+this.lastYear+"."+(this.lastMonth + 1)+".1" + timeString;
		    this.incrementMonth(this.rows*this.cols-1);
	    }
	
	    // set the desired time if available
	    if (this.timeSelector)
	    {
	        if (selDate != null)
	            this.setTime(selDate.getHours(), selDate.getMinutes(), selDate.getSeconds());
	        else
	            this.setTime(0, 0, 0);
	    }
    }
	
	// hide the calendar
	this.calendarContainer.style.display="none";
	this.iframe.style.display = "none";
	this.isVisible = false;
	document.oboutOpenCalendar = null;
	
	this.isWorking = false;
}


//Save selected dates, clears the earlier selected date if not multiple select is true
//if multiple select is true this saves the dates separated by ';'
oboutCalendar.prototype.setHiddenFieldSD = 
function(clear) {
    if (this.hiddenFieldSD != null)
    {
        var hfValue = "";
        if (!clear)
        {
            for (indexSD=0;indexSD<this.selectedDates.length;indexSD++)
            {
                hfValue += this.selectedDates[indexSD].getFullYear()+"."+(this.selectedDates[indexSD].getMonth()+1)+"."+this.selectedDates[indexSD].getDate()+";";        
            }
            
            hfValue = hfValue.substr(0, hfValue.length - 1);
        }
        
        this.hiddenFieldSD.value = hfValue;
    }
}
oboutCalendar.prototype.findPosX =
  function(obj) {
        var curleft = 0;
        if (obj.offsetParent)
            while (1) {
            curleft += obj.offsetLeft;
            if (!obj.offsetParent)
                break;
            obj = obj.offsetParent;
        }
        else if (obj.x)
            curleft += obj.x;
        return curleft;
    }

    oboutCalendar.prototype.findPosY = 
    function(obj) {
        var curtop = 0;
        if (obj.offsetParent)
            while (1) {
            curtop += obj.offsetTop;
            if (!obj.offsetParent)
                break;
            obj = obj.offsetParent;
        }
        else if (obj.y)
            curtop += obj.y;
        return curtop;
    }



    oboutCalendar.prototype.standardizeEvent = function(e) {
        if (!e) var e = window.event;
        if (!e.target) e.target = e.srcElement
        return e
    }



    oboutCalendar.prototype.createHandlerFunction = function(obj, fn) {
        var o = new Object;
        o.myObj = obj;
        o.calledFunc = fn;

        o.myFunc = function(e) {
            var e = oboutCalendar.prototype.standardizeEvent(e);
            return o.calledFunc.call(o.myObj, e);
        }
        return o.myFunc;
    }

    oboutCalendar.prototype.attachEventHandler = function(obj, evType, fn, handlerTracker, useCapture) {
        var handler = null;

        if (obj.addEventListener) {
            var handler = this.createHandlerFunction(obj, fn);
            obj.addEventListener(evType, handler, useCapture);
        } else if (obj.attachEvent) {
            var handler = this.createHandlerFunction(obj, fn);
            obj.attachEvent("on" + evType, handler);
        }

        if (handlerTracker && typeof (handlerTracker.push) == 'function') {
            var temp = new Object();
            temp['element'] = obj;
            temp['event'] = evType;
            temp['handler'] = handler;

            handlerTracker.push(temp);
        }

        return handler;
    }

    oboutCalendar.prototype.detachEventHandler = function (obj, evType, fn) {
        if (obj.removeEventListener) {
            obj.removeEventListener(evType, fn, null);
            return true;
        } else if (obj.detachEvent) {
            obj.detachEvent("on" + evType, fn);
            obj.detachEvent("on" + evType, fn);
            return true;
        }
    }